0

这是我的数据库中搜索框的编码,但是当我运行它时,它显示错误通知:未定义变量:在第 15 行的 /opt/lampp/htdocs/1234.php 中搜索然后 ii 在我的搜索框中键入任何内容它说对象未找到!

在此服务器上找不到请求的 URL。引用页面上的链接似乎是错误的或过时的。请将该错误通知该页面的作者。

如果您认为这是服务器错误,请联系网站管理员。

错误 404

本地主机 Apache/2.4.3 (Unix) OpenSSL/1.0.1c PHP/5.4.7

  <html>
  <h2>Search</h2> 
  <form name="search" method="post" action="<?=$PHP_SELF?>">
  Seach for: <input type="text" name="find" /> in 
  <Select NAME="field">
  <Option VALUE="fname">diseasename</option>
  <Option VALUE="lname">genename</option>
  </Select>
  <input type="hidden" name="searching" value="yes" />
  <input type="submit" name="search" value="Search" />
  </form>
  </html>
  <?php 
  //This is only displayed if they have submitted the form 
  if ($searching =="yes") 
  { 
  echo "<h2>Results</h2><p>"; 

  //If they did not enter a search term we give them an error 
  if ($find == "") 
  { 
  echo "<p>You forgot to enter a search term"; 
  exit; 
  } 

  // Otherwise we connect to our Database 
  mysql_connect("localhost", "root", "****") or die(mysql_error()); 
  mysql_select_db("missensencemuttation") or die(mysql_error()); 

  // We preform a bit of filtering 
  $find = strtoupper($find); 
  $find = strip_tags($find); 
  $find = trim ($find); 

  //Now we search for our search term, in the field the user specified 
  $data = mysql_query("SELECT * FROM users WHERE upper($field) LIKE'%$find%'"); 

  //And we display the results 
  while($result = mysql_fetch_array( $data )) 
  { 
  echo $result['fname']; 
  echo " "; 
  echo $result['lname']; 
  echo "<br>"; 
  echo $result['info']; 
  echo "<br>"; 
  echo "<br>"; 
  } 

  //This counts the number or results - and if there wasn't any it gives them a little message explaining that 
  $anymatches=mysql_num_rows($data); 
  if ($anymatches == 0) 
  { 
  echo "Sorry, but we can not find an entry to match your query<br><br>"; 
  } 

  //And we remind them what they searched for 
  echo "<b>Searched For:</b> " .$find; 
  } 
  ?> 

我不知道我在脚本中做错了什么。我是 php 的初学者,我正在使用互联网参考来获取 php 的知识。可以纠正这个脚本

4

2 回答 2

0

$searching目前在脚本中没有定义。我想你的意思是$_POST['searching']

在比较周围添加一个if (isset($_POST['searching'])) { //old if }以确保$_POST['searching']已设置并替换$searching$_POST['searching']

编辑:替换$PHP_SELF$_SERVER['PHP_SELF'],这可以帮助你。

于 2013-03-27T10:17:12.593 回答
0

使用如下:

extract($_POST);
 if ($searching =="yes") 
于 2013-03-27T10:16:52.590 回答