我爲自己的網站建立了自己的搜索引擎,當我搜索下面列出的任何錯誤時,我總是收到兩個錯誤,結果確實會顯示錯誤。我能做些什麼來使他們消失?消失我的意思是修復!感謝當我搜索任何東西時,搜索引擎有2個錯誤
誤差1
"(!) Notice: Undefined variable: x in C:\wamp\www\search.php on line 21"
錯誤2
"(!) Notice: Undefined variable: construct in C:\wamp\www\search.php on line 23"
這裏是我的代碼我的index.php
<html>
<head>
<title>Title of your search engine</title>
</head>
<body>
<form action='search.php' method='GET'>
<center>
<h1>My Search Engine</h1>
<input type='text' size='90' name='search'></br></br>
<input type='submit' name='submit' value='Search source code' ></br></br></br>
</center>
</form>
</body>
</html>
這裏是我的search.php代碼
<?php
$button = $_GET ['submit'];
$search = $_GET ['search'];
if(!$button){
echo "you didn't submit a keyword";
}
else
{
if(strlen($search)<=1){
echo "Search term too short";
}else{
echo "You searched for <b>$search</b> <hr size='1'></br>";
mysql_connect("localhost","root","");
mysql_select_db("search");
$search_exploded = explode (" ", $search);
foreach($search_exploded as $search_each)
{
$x++;
if($x==1)
$construct .="keywords LIKE '%$search_each%'";
else
$construct .="AND keywords LIKE '%$search_each%'";
}
$construct ="SELECT * FROM searchengine WHERE $construct";
$run = mysql_query($construct);
$foundnum = mysql_num_rows($run);
if ($foundnum==0){
echo "Sorry, there are no matching result for <b>$search</b>.</br></br>1.
Try more general words. for example: If you want to search 'how to create a website'
then use general keyword like 'create' 'website'</br>2. Try different words with similar
meaning</br>3. Please check your spelling";
}else
{
echo "$foundnum results found !<p>";
while($runrows = mysql_fetch_assoc($run))
{
$title = $runrows ['title'];
$desc = $runrows ['description'];
$url = $runrows ['url'];
echo "
<a href='$url'><b>$title</b></a><br>
$desc<br>
<a href='$url'>$url</a><p>
";
}
}
}
}
?>
初始化使用前變量...例如$ X = 0; – user1844933
**警告:**您的代碼已廣泛開放給SQL注入! – BenM
首先定義$ x和$ construct – wild