Búsqueda de secuencia de comandos en php problema

  • sohang
  • Newbie
  • Newbie
  • No Avatar
  • Registrado: Mar 30, 2009
  • Mensajes: 6
  • Status: Offline

Nota Abril 6th, 2009, 4:39 am

Tengo un problema de secuencia de comandos de búsqueda

Acabo de seguimiento de este código, pero Couldnt ejecutar la consulta

Código: [ 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.  


Muestra msg
Quote:
Warning: mysql_query (): suministrado argumento no es un recurso válido del resultado de MySQL en C: \ xampp \ htdocs \ FAQn \ searchphp. php on line 48
Resultados

Lo sentimos, su búsqueda: "A" devolvió cero resultados

Haga clic aquí para intentar la búsqueda en Google
Couldnt ejecutar la consulta


¿Dónde debería haber problema

Por favor, ayuda......
  • Anonymous
  • Bot
  • No Avatar
  • Registrado: 25 Feb 2008
  • Mensajes: ?
  • Loc: Ozzuland
  • Status: Online

Nota Abril 6th, 2009, 4:39 am

  • spork
  • Brewmaster
  • Silver Member
  • Avatar de Usuario
  • Registrado: Sep 22, 2003
  • Mensajes: 6130
  • Loc: Seattle, WA
  • Status: Offline

Nota Abril 6th, 2009, 7:27 am

Cambia esta línea:
Código: [ Select ]
$query = " limit $s,$limit";

a esto:
Código: [ Select ]
$query .= " limit $s,$limit";
The Beer Monocle. Classy.
  • sohang
  • Newbie
  • Newbie
  • No Avatar
  • Registrado: Mar 30, 2009
  • Mensajes: 6
  • Status: Offline

Nota Abril 6th, 2009, 8:33 pm

gracias a su comentario, pero aunque hay un problema

su trabajo no

problema es el mismo

Código: [ 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 Usuario
  • Registrado: Jul 06, 2004
  • Mensajes: 1890
  • Loc: Las Vegas
  • Status: Offline

Nota Abril 14th, 2009, 1:35 am

Cambiar esto:
Código: [ 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

a esto:
Código: [ 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

Tenga en cuenta que hay 2 cambios de allí (el * fue justo al lado de la DE y el orden fue escrito ORDENADO).

Y sólo para asegurarse de que, usted tiene una tabla con el nombre que con el nombre que los campos e id en ella, ¿verdad?

También: que script está listo para la inyección de SQL. Usted realmente necesita utilizar mysql_real_escape_string () en cualquier entrada que se utilizará en una consulta SQL.

Edit: ¿Mejor? :P
  • Bogey
  • Bogey
  • Genius
  • Avatar de Usuario
  • Registrado: Jul 14, 2005
  • Mensajes: 8211
  • Loc: USA
  • Status: Offline

Nota Abril 14th, 2009, 2:13 pm

Puede intentar lo siguiente para algunos propósitos de solución de problemas.

Código: [ Select ]
$numresults = mysql_query($query) or die(mysql_error());


@ ScienceOfSpock: Es obvio que usted está utilizando el tema oscuro...que el amarillo va horrible con el tema de luz ;)

Edit: Sí :)
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • Avatar de Usuario
  • Registrado: Jul 25, 2005
  • Mensajes: 2735
  • Loc: Nashville, TN
  • Status: Offline

Nota Abril 14th, 2009, 4:12 pm

Heyyyy Spock, estaba pensando combate que preguntaba el otro día cuando ya se planteó cuando alguien Captcha.
I'd love to change the world, but they won't give me the source code.
  • ScienceOfSpock
  • Mastermind
  • Mastermind
  • Avatar de Usuario
  • Registrado: Jul 06, 2004
  • Mensajes: 1890
  • Loc: Las Vegas
  • Status: Offline

Nota Abril 15th, 2009, 3:03 pm

UPSGuy escribió:
Heyyyy Spock, estaba pensando combate que preguntaba el otro día cuando ya se planteó cuando alguien Captcha.


Ive sido muy activo últimamente, y no tuvo tiempo para visitar Ozzu pero una vez cada semana o dos. Estaba trabajando para Filefront. com, pero el trabajo desapareció a finales de marzo de Ziff Davis cuando decidió matar al sitio, por lo que Ive tengo algo de tiempo libre ahora :)
  • PolishHurricane
  • Mastermind
  • Mastermind
  • Avatar de Usuario
  • Registrado: Feb 17, 2005
  • Mensajes: 1585
  • Status: Offline

Nota Abril 15th, 2009, 6:52 pm

Didnt venden de nuevo a los fundadores originales de la página web? He leído acerca de que esta mañana. Se organizó un juego fresco mod que Im que interested in
There's no place like 127.0.0.1, badass part is now it's ::1
  • Bogey
  • Bogey
  • Genius
  • Avatar de Usuario
  • Registrado: Jul 14, 2005
  • Mensajes: 8211
  • Loc: USA
  • Status: Offline

Nota Abril 15th, 2009, 7:01 pm

PolishHurricane escribió:
Didnt venden de nuevo a los fundadores originales de la página web? He leído acerca de que esta mañana. Se organizó un juego fresco mod que Im que interested in

Lo hicieron...los "fundadores" como lo llamaron, lo compró...es por eso que el sitio se encuentra trabajando. Eso es lo que he leído sobre él cerca de una hora o así lo hace.
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • PolishHurricane
  • Mastermind
  • Mastermind
  • Avatar de Usuario
  • Registrado: Feb 17, 2005
  • Mensajes: 1585
  • Status: Offline

Nota Abril 16th, 2009, 4:13 am

Fresco, pequeño mundo.
There's no place like 127.0.0.1, badass part is now it's ::1

Publicar Información

  • Total de mensajes en este tema: 10 mensajes
  • Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 161 invitados
  • No puede abrir nuevos temas en este Foro
  • No puede responder a temas en este Foro
  • No puede editar sus mensajes en este Foro
  • No puede borrar sus mensajes en este Foro
  • No puede enviar adjuntos en este Foro
 
 

© 2011 Unmelted, LLC. Ozzu® es una marca registrada de Unmelted, LLC