| | |
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
![]() |
0
#21 Nov 8th, 2009
well if ur search function is working fine then i guess the problem is with some other line...
why dont u post up the exact warning message and the code which is throwing it...
why dont u post up the exact warning message and the code which is throwing it...
Gimme reputation points if u find my post helpful.
use [code] tags wherever applicable
dont start a new thread unless u cant find the topic already on forum.
mark a thread "solved" as soon as u get a solution
use [code] tags wherever applicable
dont start a new thread unless u cant find the topic already on forum.
mark a thread "solved" as soon as u get a solution
0
#23 Nov 8th, 2009
well i cant see a line 38 in ur code... it ends in 21 lines... i believe u r posting only half of the file...
and as far as names are concerned it wont make any difference unless u r using dose names to refer to those files from within ur code. Its not a gr8 practice to change file names after u have started writing code in them. just determine what that file is meant to do beforehand and name it accordingly...
For now i will suggest u to post the full code u have written in admin_loggedin_search_admin.php file
and as far as names are concerned it wont make any difference unless u r using dose names to refer to those files from within ur code. Its not a gr8 practice to change file names after u have started writing code in them. just determine what that file is meant to do beforehand and name it accordingly...
For now i will suggest u to post the full code u have written in admin_loggedin_search_admin.php file
•
•
•
•
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\admin_loggedin_search_admin.php on line 38....and the code is same as above....Does the name of the file make any difference in PHP.for instance saving a file as loginpage.php or login_page.php
Gimme reputation points if u find my post helpful.
use [code] tags wherever applicable
dont start a new thread unless u cant find the topic already on forum.
mark a thread "solved" as soon as u get a solution
use [code] tags wherever applicable
dont start a new thread unless u cant find the topic already on forum.
mark a thread "solved" as soon as u get a solution
0
#24 Nov 8th, 2009
Try this.
Also with the above code it should have a pretty good debugging error if it fails. So run the above script and tell me what the new error is if any.
php Syntax (Toggle Plain Text)
$query = 'SELECT * FROM `administrator` WHERE `'.mysql_real_escape_string($_POST['searchby']).'` LIKE "%'.mysql_real_escape_string($_POST['query']).'%"'; mysql_query($query) or die('SQL Syntax Error - query was: <u>'.$query.'</u><hr>'.mysql_error());
Last edited by cwarn23; Nov 8th, 2009 at 7:04 am. Reason: bugs
Try not to bump 10 year old topics as it can be really annoying.
http://syntax.cwarn23.net/
My favourite PC. -- Jumba webhosting
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*` Want 1 on 1 php help, add me to msn at msn@cwarn23.infoMy favourite PC. -- Jumba webhosting
•
•
Join Date: Nov 2009
Posts: 7
Reputation:
Solved Threads: 0
-1
#25 Nov 8th, 2009
now the search functionality has failed.....error:
SQL Syntax Error - query was:
Unknown column '' in 'where clause'
code is
SQL Syntax Error - query was:
Unknown column '' in 'where clause'
code is
PHP Syntax (Toggle Plain Text)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Search for Administrators</title> </head> <body bgcolor="#FF9900" text="#FFFFCC" link="#FFFFFF" vlink="#FF3300" alink="#FFFF00"> <table width="1080"> <tr> <td width="710"> <p>Search For Administrators <hr size="1"> <p/> <form action="admin_loggedin_search_admin.php" method="post"> Search by : <select name="searchby"> <option value="" SELECTED>-Select One-</option> <option value="name" >Name</option> <option value="state">State</option> <option value="username">Username</option> </select> <input type="text" name="query" size="10" maxlength="100" > <input type="submit" name="submit" value="submit"> <?php $con = mysql_connect("localhost","root",""); if(!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("polling",$con); $query1 = "SELECT * FROM administrator WHERE ".$_POST[searchby]." like '%".$_POST[query]."%'"; $result = mysql_query($query1); //$result=mysql_query("SELECT * FROM administrator WHERE $_POST[searchby] LIKE '%$_POST[query]%'" ); //$query1 = 'SELECT * FROM `administrator` WHERE `'.mysql_real_escape_string($_POST['searchby']).'` LIKE "%'.mysql_real_escape_string($_POST['query']).'%"'; //mysql_query($query1) or die('SQL Syntax Error - query was: <u>'.$query.'</u><hr>'.mysql_error()); $found=0; while($sri=mysql_fetch_array($result)) { if($sri['name']!="") { $found++; echo "<br /> ".$sri['name']."->".$sri['username']; } } if($found!=0) {echo "<br />Found ".$found." results!";} /*if(!mysql_query($sri,$con)) { die('Error: '.mysql_error()); }*/ mysql_close($con) ?> <td width="270"> <td width="170"> <p>Search For <hr size="1"> </p> <a href="admin_loggedin_search_voter.php" title="Search for Voters" >Voters</a> <p><a href="admin_loggedin_search_candidate.php" title="Search for Candidates" >Candidates</a></p> <p><a href="admin_loggedin_search_officer.php" title="Search for Officers" >Officers</a></p> <tr/> </table> </body> </html>
•
•
Join Date: Nov 2009
Posts: 7
Reputation:
Solved Threads: 0
-1
#26 Nov 8th, 2009
now line 38 is line 40...save code as any xyz.php....modify form action as xyz.php and u can see the error...
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\admin_loggedin_search_admin.php on line 40
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\admin_loggedin_search_admin.php on line 40
Last edited by srinivasjinde; Nov 8th, 2009 at 11:58 am.
0
#27 Nov 8th, 2009
Try this:
php Syntax (Toggle Plain Text)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Search for Administrators</title> </head> <body bgcolor="#FF9900" text="#FFFFCC" link="#FFFFFF" vlink="#FF3300" alink="#FFFF00"> <table width="1080"> <tr> <td width="710"> <p>Search For Administrators <hr size="1"> <p/> <form action="admin_loggedin_search_admin.php" method="post"> Search by : <select name="searchby"> <option value="" SELECTED>-Select One-</option> <option value="name" >Name</option> <option value="state">State</option> <option value="username">Username</option> </select> <input type="text" name="query" size="10" maxlength="100" > <input type="submit" name="submit" value="submit"> <?php $con = mysql_connect("localhost","root",""); if(!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("polling",$con); $query1 = 'SELECT * FROM `administrator` WHERE `'.mysql_real_escape_string($_POST['searchby']).'` LIKE "%'.mysql_real_escape_string($_POST['query']).'%"'; mysql_query($query1) or die('SQL Syntax Error - query was: <u>'.$query.'</u><hr>'.mysql_error()); $found=0; while($sri=mysql_fetch_array($result)) { if($sri['name']!="") { $found++; echo "<br /> ".$sri['name']."->".$sri['username']; } } if($found!=0) {echo "<br />Found ".$found." results!";} /*if(!mysql_query($sri,$con)) { die('Error: '.mysql_error()); }*/ mysql_close($con) ?> <td width="270"> <td width="170"> <p>Search For <hr size="1"> </p> <a href="admin_loggedin_search_voter.php" title="Search for Voters" >Voters</a> <p><a href="admin_loggedin_search_candidate.php" title="Search for Candidates" >Candidates</a></p> <p><a href="admin_loggedin_search_officer.php" title="Search for Officers" >Officers</a></p> <tr/> </table> </body> </html>
Try not to bump 10 year old topics as it can be really annoying.
http://syntax.cwarn23.net/
My favourite PC. -- Jumba webhosting
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*` Want 1 on 1 php help, add me to msn at msn@cwarn23.infoMy favourite PC. -- Jumba webhosting
1
#28 Nov 9th, 2009
There you go... the prob is not in the query statement bt its about the post variables... when the page loads for first time u dont have any values in ur post variables and thus it returns an error which gets disappeared as soon as u try searching because then u have some values in post.
So the solution for this is to place ur database access section inside an if statement which will enable search in database only when u ve got values in post variables.. something like this..
This should solve ur problem..
Cheers !!
edit: I just noticed in ur statement u have missed single quotes while accessing the post variables... i wonder how u didnt get an error fr that!!
So the solution for this is to place ur database access section inside an if statement which will enable search in database only when u ve got values in post variables.. something like this..
PHP Syntax (Toggle Plain Text)
if(!empty($_POST['searchby']) && !empty($_POST['query'])){ $query1 = "SELECT * FROM user_tbl WHERE ".$_POST['searchby']." like '%".$_POST['query']."%'"; $result = mysql_query($query1); $found=0; while($sri=mysql_fetch_array($result)) { if($sri['name']!="") { $found++; echo "<br /> ".$sri['name']."->".$sri['username']; } } if($found!=0) {echo "<br />Found ".$found." results!";} }
This should solve ur problem..
Cheers !!
•
•
•
•
now the search functionality has failed.....error:
SQL Syntax Error - query was:
Unknown column '' in 'where clause'
code is
PHP Syntax (Toggle Plain Text)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Search for Administrators</title> </head> <body bgcolor="#FF9900" text="#FFFFCC" link="#FFFFFF" vlink="#FF3300" alink="#FFFF00"> <table width="1080"> <tr> <td width="710"> <p>Search For Administrators <hr size="1"> <p/> <form action="admin_loggedin_search_admin.php" method="post"> Search by : <select name="searchby"> <option value="" SELECTED>-Select One-</option> <option value="name" >Name</option> <option value="state">State</option> <option value="username">Username</option> </select> <input type="text" name="query" size="10" maxlength="100" > <input type="submit" name="submit" value="submit"> <?php $con = mysql_connect("localhost","root",""); if(!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("polling",$con); $query1 = "SELECT * FROM administrator WHERE ".$_POST[searchby]." like '%".$_POST[query]."%'"; $result = mysql_query($query1); //$result=mysql_query("SELECT * FROM administrator WHERE $_POST[searchby] LIKE '%$_POST[query]%'" ); //$query1 = 'SELECT * FROM `administrator` WHERE `'.mysql_real_escape_string($_POST['searchby']).'` LIKE "%'.mysql_real_escape_string($_POST['query']).'%"'; //mysql_query($query1) or die('SQL Syntax Error - query was: <u>'.$query.'</u><hr>'.mysql_error()); $found=0; while($sri=mysql_fetch_array($result)) { if($sri['name']!="") { $found++; echo "<br /> ".$sri['name']."->".$sri['username']; } } if($found!=0) {echo "<br />Found ".$found." results!";} /*if(!mysql_query($sri,$con)) { die('Error: '.mysql_error()); }*/ mysql_close($con) ?> <td width="270"> <td width="170"> <p>Search For <hr size="1"> </p> <a href="admin_loggedin_search_voter.php" title="Search for Voters" >Voters</a> <p><a href="admin_loggedin_search_candidate.php" title="Search for Candidates" >Candidates</a></p> <p><a href="admin_loggedin_search_officer.php" title="Search for Officers" >Officers</a></p> <tr/> </table> </body> </html>
Last edited by venkat0904; Nov 9th, 2009 at 1:45 am.
Gimme reputation points if u find my post helpful.
use [code] tags wherever applicable
dont start a new thread unless u cant find the topic already on forum.
mark a thread "solved" as soon as u get a solution
use [code] tags wherever applicable
dont start a new thread unless u cant find the topic already on forum.
mark a thread "solved" as soon as u get a solution
•
•
Join Date: Nov 2009
Posts: 7
Reputation:
Solved Threads: 0
0
#29 Nov 10th, 2009
yes...got it!!I should have understood that...my problem is solved guys!!Thank you all for the patience you have showed...
@venkat...when i missed the single quotes i didnt get any error and the search func. is working fine..even i dont know how it happened....anyways...thanks again for your co-operation.
@venkat...when i missed the single quotes i didnt get any error and the search func. is working fine..even i dont know how it happened....anyways...thanks again for your co-operation.
0
#30 Nov 11th, 2009
kool... all well that ends well 

•
•
•
•
yes...got it!!I should have understood that...my problem is solved guys!!Thank you all for the patience you have showed...
@venkat...when i missed the single quotes i didnt get any error and the search func. is working fine..even i dont know how it happened....anyways...thanks again for your co-operation.
Gimme reputation points if u find my post helpful.
use [code] tags wherever applicable
dont start a new thread unless u cant find the topic already on forum.
mark a thread "solved" as soon as u get a solution
use [code] tags wherever applicable
dont start a new thread unless u cant find the topic already on forum.
mark a thread "solved" as soon as u get a solution
![]() |
Similar Threads
- Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource (PHP)
- Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource (PHP)
- Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource (MySQL)
- Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource (PHP)
- Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource (PHP)
Other Threads in the PHP Forum
- Previous Thread: Newbie PHP question re:w3schools
- Next Thread: textarea count commas.
Views: 90803 | Replies: 29
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array auto box broken buttons cakephp check checkbox class classes cms code cookies database date development directory display download dropdown dropdownlist drupal dynamic echo email error file files folder form forms function functions header href htaccess html image images include insert ip java javascript joomla jquery limit link login loop mail menu mlm mod_rewrite multiple mysql order parse password paypal php problem query radio redirect regex remote rows script search security select server session soap sort sorting source sql string structure syntax table unicode update upload url user validation variable video web website wordpress xml






