| | |
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
0
#21 21 Days Ago
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 21 Days Ago
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 21 Days Ago
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; 21 Days Ago at 8:04 am. Reason: bugs
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
•
•
Join Date: Nov 2009
Posts: 7
Reputation:
Solved Threads: 0
-1
#25 21 Days Ago
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 21 Days Ago
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; 21 Days Ago at 12:58 pm.
0
#27 20 Days Ago
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 threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
1
#28 20 Days Ago
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; 20 Days Ago at 2: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 18 Days Ago
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 18 Days Ago
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.
| Thread Tools | Search this Thread |
# 5.2.10 access alexa apache api array beginner binary broken cakephp checkbox class clean clients cms code cron curl database date directory display dissertation dynamic echo echo$_get[x]changingitintovariable... email encode error fairness file files folder form forms function functions google href htaccess html image images include indentedsubcategory insert ip javascript joomla legislation limit link local login mail memberships menu mlm multiple multipletables mysql mysqlquery newsletters oop open paypal pdf persist php problem provider query radio random recursion remote rss script search server sessions sms sockets source space spam sql syntax system table tutorial update upload url validator variable video web youtube






