Recherche script php problème dans

  • sohang
  • Newbie
  • Newbie
  • No Avatar
  • Inscription: Mar 30, 2009
  • Messages: 6
  • Status: Offline

Message Avril 6th, 2009, 4:39 am

J'ai un problème de script de recherche

Je suis juste en place ce code mais il Couldnt exécuter la requête

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


Il montre msg
Quote:
Warning: mysql_num_rows (): l'argument fourni n'est pas valide ressource de résultat MySQL dans C: \ xampp \ htdocs \ FAQn \ searchphp. php on line 48
Résultats

Désolé, votre recherche: "a" est retourné aucun résultat

Cliquez ici pour essayer la recherche sur google
Couldnt exécuter la requête


Où doit avoir problème

S'il vous plaît aider......
  • Anonymous
  • Bot
  • No Avatar
  • Inscription: 25 Feb 2008
  • Messages: ?
  • Loc: Ozzuland
  • Status: Online

Message Avril 6th, 2009, 4:39 am

  • spork
  • Brewmaster
  • Silver Member
  • Avatar de l’utilisateur
  • Inscription: Sep 22, 2003
  • Messages: 6128
  • Loc: Seattle, WA
  • Status: Offline

Message Avril 6th, 2009, 7:27 am

Modifiez cette ligne:
Code: [ Select ]
$query = " limit $s,$limit";

à ceci:
Code: [ Select ]
$query .= " limit $s,$limit";
The Beer Monocle. Classy.
  • sohang
  • Newbie
  • Newbie
  • No Avatar
  • Inscription: Mar 30, 2009
  • Messages: 6
  • Status: Offline

Message Avril 6th, 2009, 8:33 pm

merci de votre commentaire, mais bien qu'il y ait un problème

sa ne fonctionne pas

problème est le même

Code: [ Select ]
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\FAQn\searchphp.php on line 48
  • ScienceOfSpock
  • Mastermind
  • Mastermind
  • Avatar de l’utilisateur
  • Inscription: Juil 06, 2004
  • Messages: 1890
  • Loc: Las Vegas
  • Status: Offline

Message Avril 14th, 2009, 1:35 am

Changer cela:
Code: [ Select ]
$query = "SELECT *FROM que WHERE que LIKE \'%$trimmed%\'
  ORDERD BY id"; // EDIT HERE and specify your table and field names for the SQL query
  1. $query = "SELECT *FROM que WHERE que LIKE \'%$trimmed%\'
  2.   ORDERD BY id"; // EDIT HERE and specify your table and field names for the SQL query

à ceci:
Code: [ Select ]
$query = "SELECT * FROM que WHERE que LIKE \'%$trimmed%\' ORDER BY id ASC"; // EDIT HERE and specify your table and field names for the SQL query

Remarque: Il ya 2 changements, il (le * est juste à côté du DE et ordre a été commandés en orthographe).

Et juste pour s'assurer que vous n'avez que une table nommée avec les champs nom et id que dedans, non?

AUSSI: Ce script est mûr pour l'injection SQL. Vous avez vraiment besoin d'utiliser mysql_real_escape_string () sur toutes les interventions qui seront utilisées dans une requête SQL.

Edit: Mieux? :P
  • Bogey
  • Bogey
  • Genius
  • Avatar de l’utilisateur
  • Inscription: Juil 14, 2005
  • Messages: 8211
  • Loc: USA
  • Status: Offline

Message Avril 14th, 2009, 2:13 pm

Vous pouvez essayer ce qui suit à certaines fins de dépannage.

Code: [ Select ]
$numresults = mysql_query($query) or die(mysql_error());


@ ScienceOfSpock: Il est évident que vous utilisez le thème sombre...que le jaune va horrible avec le thème de la lumière ;)

Edit: Ouais :)
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • Avatar de l’utilisateur
  • Inscription: Juil 25, 2005
  • Messages: 2735
  • Loc: Nashville, TN
  • Status: Offline

Message Avril 14th, 2009, 4:12 pm

Heyyyy Spock, je viens juste vous thinkin bout l'autre jour, se demandant où étaient lorsque quelqu'un ya mis Captcha.
I'd love to change the world, but they won't give me the source code.
  • ScienceOfSpock
  • Mastermind
  • Mastermind
  • Avatar de l’utilisateur
  • Inscription: Juil 06, 2004
  • Messages: 1890
  • Loc: Las Vegas
  • Status: Offline

Message Avril 15th, 2009, 3:03 pm

UPSGuy a écrit:
Heyyyy Spock, je viens juste vous thinkin bout l'autre jour, se demandant où étaient lorsque quelqu'un ya mis Captcha.


Jai été très occupé ces derniers temps, et n'a pas eu le temps de visiter Ozzu, mais une fois par semaine ou deux. Travaillait pour Filefront. com, mais les emplois ont disparu à la fin du mois de Mars lors de Ziff Davis a décidé de tuer le site, afin Ive a obtenu peu de temps libre maintenant :)
  • PolishHurricane
  • Mastermind
  • Mastermind
  • Avatar de l’utilisateur
  • Inscription: Fév 17, 2005
  • Messages: 1585
  • Status: Offline

Message Avril 15th, 2009, 6:52 pm

Didnt qu'ils vendent à l'origine les fondateurs du site web? J'ai lu à ce sujet ce matin. Ils ont accueilli un mod de jeu cool que Im intéressé po
There's no place like 127.0.0.1, badass part is now it's ::1
  • Bogey
  • Bogey
  • Genius
  • Avatar de l’utilisateur
  • Inscription: Juil 14, 2005
  • Messages: 8211
  • Loc: USA
  • Status: Offline

Message Avril 15th, 2009, 7:01 pm

PolishHurricane a écrit:
Didnt qu'ils vendent à l'origine les fondateurs du site web? J'ai lu à ce sujet ce matin. Ils ont accueilli un mod de jeu cool que Im intéressé po

Ils n'ont...les "fondateurs" comme ils l'appelaient, a acheté...C'est la raison pour laquelle le site est encore en activité. C'est ce que j'ai lu à ce sujet sur une heure, il ya.
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • PolishHurricane
  • Mastermind
  • Mastermind
  • Avatar de l’utilisateur
  • Inscription: Fév 17, 2005
  • Messages: 1585
  • Status: Offline

Message Avril 16th, 2009, 4:13 am

Cool, petit monde.
There's no place like 127.0.0.1, badass part is now it's ::1

Afficher de l'information

  • Total des messages de ce sujet: 10 messages
  • Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 218 invités
  • Vous ne pouvez pas poster de nouveaux sujets
  • Vous ne pouvez pas répondre aux sujets
  • Vous ne pouvez pas éditer vos messages
  • Vous ne pouvez pas supprimer vos messages
  • Vous ne pouvez pas joindre des fichiers
 
 

© 2011 Unmelted, LLC. Ozzu® est une marque déposée de Unmelted, LLC