query not match

  • sohang
  • Newbie
  • Newbie
  • sohang
  • Posts: 6

Post 3+ Months Ago

I apply this script on my page but its not match any of my query of localhost database.

please help me//..

Code: [ Select ]
<html>
<head>
<title>search script</title>
<meta name="author" content="Steve R">
</head>
<body>
 
<form name="form" action="searchphp.php" method="get">
  <input type="text" name="q" />
  <input type="submit" name="Submit" value="Search" />
</form>
 
<?php
 
  // Get the search variable from URL
 
  $var = @$_GET['q'] ;
  $trimmed = trim($var) ;//trim whitespace from the stored variable
 
// rows to return
$limit=10 ;
 
// check for an empty string and display a message.
if ($trimmed == "")
  {
  echo "<p>Please enter a search...</p>";
  exit;
  }
 
// check for a search parameter
if (!isset($var))
  {
  echo "<p>We dont seem to have a search parameter!</p>";
  exit;
  }
 
//connect to your database ** EDIT REQUIRED HERE **
mysql_connect("localhost","root",""); //(host, username, password)
 
//specify database ** EDIT REQUIRED HERE **
mysql_select_db("apnahome") or die("Unable to select database"); //select which database we're using
 
// Build SQL Query
$query = "SELECT *FORM register WHERE register LIKE \'%$trimmed%\'
  ORDERD BY register"; // EDIT HERE and specify your table and field names for the SQL query
 
 $numresults = mysql_query($query);
 $numrows = mysql_num_rows($numresults);
 
// If we have no results, offer a google search as an alternative
 
if ($numrows == 0)
  {
  echo "<h4>Results</h4>";
  echo "<p>Sorry, your search: &quot;" . $trimmed . "&quot; returned zero results</p>";
 
// google
 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>";
  }
 
// next determine if s has been passed to script, if not use 0
  if (empty($s)) {
  $s=0;
  }
 
// get results
  $query = " limit $s,$limit";
  $result = mysql_query($query) or die("Couldn't execute query");
 
// display what the person searched for
echo "<p>You searched for: &quot;" . $var . "&quot;</p>";
 
// begin to show results set
echo "Results";
$count = 1 + $s ;
 
// now you can display the results returned
  while ($row= mysql_fetch_array($result)) {
  $title = $row["1st_field"];
 
  echo "$count.)&nbsp;$title" ;
  $count++ ;
  }
 
$currPage = (($s/$limit) + 1);
 
//break before paging
  echo "<br />";
 
  // next we need to do the links to other results
  if ($s>=1) { // bypass PREV link if s is 0
  $prevs=($s-$limit);
  print "&nbsp;<a href=\"$PHP_SELF?s=$prevs&q=$var\">&lt;&lt;
  Prev 10</a>&nbsp&nbsp;";
  }
 
// calculate number of pages needing links
  $pages=intval($numrows/$limit);
 
// $pages now contains int of pages needed unless there is a remainder from division
 
  if ($numrows%$limit) {
  // has remainder so add one page
  $pages++;
  }
 
// check to see if last page
  if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {
 
  // not last page so give NEXT link
  $news=$s+$limit;
 
  echo "&nbsp;<a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 &gt;&gt;</a>";
  }
 
$a = $s + ($limit) ;
  if ($a > $numrows) { $a = $numrows ; }
  $b = $s + 1 ;
  echo "<p>Showing results $b to $a of $numrows</p>";
 
?>
 
<!-- © http://www.designplace.org/ -->
 
</body>
</html>
  1. <html>
  2. <head>
  3. <title>search script</title>
  4. <meta name="author" content="Steve R">
  5. </head>
  6. <body>
  7.  
  8. <form name="form" action="searchphp.php" method="get">
  9.   <input type="text" name="q" />
  10.   <input type="submit" name="Submit" value="Search" />
  11. </form>
  12.  
  13. <?php
  14.  
  15.   // Get the search variable from URL
  16.  
  17.   $var = @$_GET['q'] ;
  18.   $trimmed = trim($var) ;//trim whitespace from the stored variable
  19.  
  20. // rows to return
  21. $limit=10 ;
  22.  
  23. // check for an empty string and display a message.
  24. if ($trimmed == "")
  25.   {
  26.   echo "<p>Please enter a search...</p>";
  27.   exit;
  28.   }
  29.  
  30. // check for a search parameter
  31. if (!isset($var))
  32.   {
  33.   echo "<p>We dont seem to have a search parameter!</p>";
  34.   exit;
  35.   }
  36.  
  37. //connect to your database ** EDIT REQUIRED HERE **
  38. mysql_connect("localhost","root",""); //(host, username, password)
  39.  
  40. //specify database ** EDIT REQUIRED HERE **
  41. mysql_select_db("apnahome") or die("Unable to select database"); //select which database we're using
  42.  
  43. // Build SQL Query
  44. $query = "SELECT *FORM register WHERE register LIKE \'%$trimmed%\'
  45.   ORDERD BY register"; // EDIT HERE and specify your table and field names for the SQL query
  46.  
  47.  $numresults = mysql_query($query);
  48.  $numrows = mysql_num_rows($numresults);
  49.  
  50. // If we have no results, offer a google search as an alternative
  51.  
  52. if ($numrows == 0)
  53.   {
  54.   echo "<h4>Results</h4>";
  55.   echo "<p>Sorry, your search: &quot;" . $trimmed . "&quot; returned zero results</p>";
  56.  
  57. // google
  58.  echo "<p><a href=\"http://www.google.com/search?q="
  59.   . $trimmed . "\" target=\"_blank\" title=\"Look up
  60.   " . $trimmed . " on Google\">Click here</a> to try the
  61.   search on google</p>";
  62.   }
  63.  
  64. // next determine if s has been passed to script, if not use 0
  65.   if (empty($s)) {
  66.   $s=0;
  67.   }
  68.  
  69. // get results
  70.   $query = " limit $s,$limit";
  71.   $result = mysql_query($query) or die("Couldn't execute query");
  72.  
  73. // display what the person searched for
  74. echo "<p>You searched for: &quot;" . $var . "&quot;</p>";
  75.  
  76. // begin to show results set
  77. echo "Results";
  78. $count = 1 + $s ;
  79.  
  80. // now you can display the results returned
  81.   while ($row= mysql_fetch_array($result)) {
  82.   $title = $row["1st_field"];
  83.  
  84.   echo "$count.)&nbsp;$title" ;
  85.   $count++ ;
  86.   }
  87.  
  88. $currPage = (($s/$limit) + 1);
  89.  
  90. //break before paging
  91.   echo "<br />";
  92.  
  93.   // next we need to do the links to other results
  94.   if ($s>=1) { // bypass PREV link if s is 0
  95.   $prevs=($s-$limit);
  96.   print "&nbsp;<a href=\"$PHP_SELF?s=$prevs&q=$var\">&lt;&lt;
  97.   Prev 10</a>&nbsp&nbsp;";
  98.   }
  99.  
  100. // calculate number of pages needing links
  101.   $pages=intval($numrows/$limit);
  102.  
  103. // $pages now contains int of pages needed unless there is a remainder from division
  104.  
  105.   if ($numrows%$limit) {
  106.   // has remainder so add one page
  107.   $pages++;
  108.   }
  109.  
  110. // check to see if last page
  111.   if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {
  112.  
  113.   // not last page so give NEXT link
  114.   $news=$s+$limit;
  115.  
  116.   echo "&nbsp;<a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 &gt;&gt;</a>";
  117.   }
  118.  
  119. $a = $s + ($limit) ;
  120.   if ($a > $numrows) { $a = $numrows ; }
  121.   $b = $s + 1 ;
  122.   echo "<p>Showing results $b to $a of $numrows</p>";
  123.  
  124. ?>
  125.  
  126. <!-- © http://www.designplace.org/ -->
  127.  
  128. </body>
  129. </html>


And this msg are showing

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\FAQn\searchphp.php on line 147
Results

Sorry, your search: "a" returned zero results

Click here to try the search on google
Couldn't execute query


please help
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6243
  • Loc: Seattle, WA

Post 3+ Months Ago

Code: [ Select ]
$query = "SELECT *FORM register


It's SELECT FROM, not SELECT FORM.

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 102 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.