Whats wrong here?
It say: Notice: Undefined variable: var in C:\wamp\www\work\search\search.php on line 3
index.php
Code: Select all
<form name=form action=search.php method=get>
  <input type=text name=q >
  <input type=submit name=Submit value=Search >
</form>Code: Select all
<?php
  $trimmed = trim($var);
  $limit=10;
  if ($trimmed == ""){
   echo "<p>Please enter a search...</p>";
   exit;
  }
 if (!isset($var)){
   echo "<p>We dont seem to have a search parameter!</p>";
   exit;
  }
 mysql_connect("localhost","root",""); 
 mysql_select_db("Areox") or die("Unable to select database");
 $query = "select * from the_table where 1st_field like \"%$trimmed%\" order by 1st_field";
 $numresults=mysql_query($query);
 $numrows=mysql_num_rows($numresults);
if ($numrows == 0)
  {
   echo "<h4>Results</h4>";
   echo "<p>Sorry, your search: " . $trimmed . " returned zero results</p>";
   echo "<p><a href=\"http://www.google.com/search?q="
   . $trimmed . "\" target=\"_blank\" title=\"Look up
   " . $trimmed . " on Google\">Click here</a> to try the
   search on google</p>";
  }
  if (empty($s)) {
 $s=0;
  }
  $query .= " limit $s,$limit";
  $result = mysql_query($query) or die("Couldn't execute query");
 echo "<p>You searched for: " . $var . "</p>";
 echo "Results";
 $count = 1 + $s ;
  while ($row= mysql_fetch_array($result)) {
  $title = $row["1st_field"];
  echo "$count.) $title" ;
  $count++ ;
  }
$currPage = (($s/$limit) + 1);
  echo "<br />";
  if ($s>=1) { // bypass PREV link if s is 0
  $prevs=($s-$limit);
  print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><<
  Prev 10</a>  ";
  }
  $pages=intval($numrows/$limit);
  if ($numrows%$limit) {
  $pages++;
  }
  if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {
  $news=$s+$limit;
  echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>";
  }
  $a = $s + ($limit) ;
  if ($a > $numrows) { $a = $numrows ; }
  $b = $s + 1 ;
  echo "<p>Showing results $b to $a of $numrows</p>";
 
?>
