Re: creating the php search script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



ok dude some suggestions for you 

For the query please use mysql_escape() or mysql_realescape() when executing scripts in sql .

Use phpmyadmin or what ever you like to check whether the query works right . 

Use an echo statement to print the query, keep an exit and test it with values .....

Eg : "select * from table where 1st_field like studentID=' ". mysql_escape( $
studentsID )." ' , Name='".  mysql_escape($ Name) . " ', address= ' ".  mysql_escape($address) ." ' ,phone='".  mysql_escape($ phone) ." ',sex=
'". mysql_escape( $sex ) ." ', DOB= ' ".  mysql_escape( $DOB ) . "  order by 1st_field"; 

 $numresults= mysql_query( $query2);

It seems your query itself is wrong . You need to refer mysql select stament 

Hari K T

http://harikt.com/


--- On Sat, 8/8/09, Gab Teo <doneatlast1000@xxxxxxxxx> wrote:

From: Gab Teo <doneatlast1000@xxxxxxxxx>
Subject:  creating the php search script
To: php-objects@xxxxxxxxxxxxxxx
Date: Saturday, 8 August, 2009, 1:33 AM






 




    
                  Please, I need help, I am trying to create a search on a website, the below error ( $numrows=mysql_ num_rows( $numresults) ; line 57) keep showing even after I have create the sql query in many forms, the error highlited in blue and the lne of the error in red on the php scrpt.

Gab

 



Warning: mysql_num_rows( ): supplied argument is not a valid MySQL result resource in C:\Inetpub\wwwroot\ mydatabase\ search.php on line 57

Results

Sorry, your search: "john" returned zero results

Couldn't execute query 

 

 

<?php



  $var = @$_GET['q'] ;

  $trimmed = trim($var); //trim whitespace from the stored variable



$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"," "); //(host, username, password)



mysql_select_ db("mydatabase" ) or die("Unable to select database"); //select which database we're using

  

$query = "select * from table where 1st_field like studentID='$ studentsID' ,'Name='$ Name',address= '$address' ,phone='$ phone',sex= '$sex',DOB= '$DOB' \"%$trimmed% \"  

  order by 1st_field"; 

 $numresults= mysql_query( $query2);

 $numrows=mysql_ num_rows( $numresults) ; This is the line 57 

 

if ($numrows == 0)

  {

  echo "<h4>Results< /h4>";

  echo "<p>Sorry, your search: &quot;" . $trimmed . "&quot; returned zero results</p>" ;



  }



  if (empty($s)) {

  $s=0;

  }



  $query = " limit $s,$limit";

  $result = mysql_query( $query2) or die("Couldn' t execute query");



echo "<p>You searched for: &quot;" . $var . "&quot;</p>" ;



echo "Results";

$count = 1 + $s ;



  while ($row= mysql_fetch_ array($result) ) {

  $title = $row["1st_field" ];

  echo "$count.)&nbsp; $title" ;

  $count++ ;

  }

$currPage = (($s/$limit) + 1);



  echo "<br />";

  

  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;";

  }



  $pages=intval( $numrows/ $limit);

 

  if ($numrows%$limit) {

  

  $pages++;

  }



  if (!((($s+$limit) /$limit)= =$pages) && $pages!=1) {

  $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> ";

  

?>



[Non-text portions of this message have been removed]




 

      

    
    
	
	 
	
	








	


	
	


      Looking for local information? Find it on Yahoo! Local http://in.local.yahoo.com/

[Non-text portions of this message have been removed]


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux