Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result

Reply

Join Date: Oct 2009
Posts: 151
Reputation: venkat0904 is an unknown quantity at this point 
Solved Threads: 15
venkat0904's Avatar
venkat0904 venkat0904 is offline Offline
Junior Poster
 
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...

Originally Posted by srinivasjinde View Post
The prob. is still there....anyway the search functionality is working well....the only thing is that the warning msg doesnt look good....and when i do the first search by entering a query....i get the search results and the error msg disappears...
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 7
Reputation: srinivasjinde is an unknown quantity at this point 
Solved Threads: 0
srinivasjinde srinivasjinde is offline Offline
Newbie Poster
 
-1
  #22
21 Days Ago
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 151
Reputation: venkat0904 is an unknown quantity at this point 
Solved Threads: 15
venkat0904's Avatar
venkat0904 venkat0904 is offline Offline
Junior Poster
 
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

Originally Posted by srinivasjinde View Post
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,463
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 136
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Nearly a Posting Virtuoso
 
0
  #24
21 Days Ago
Try this.
  1. $query = 'SELECT * FROM `administrator` WHERE `'.mysql_real_escape_string($_POST['searchby']).'` LIKE "%'.mysql_real_escape_string($_POST['query']).'%"';
  2. mysql_query($query) or die('SQL Syntax Error - query was: <u>'.$query.'</u><hr>'.mysql_error());
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.
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 7
Reputation: srinivasjinde is an unknown quantity at this point 
Solved Threads: 0
srinivasjinde srinivasjinde is offline Offline
Newbie Poster
 
-1
  #25
21 Days Ago
now the search functionality has failed.....error:
SQL Syntax Error - query was:

Unknown column '' in 'where clause'


code is
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <title>Search for Administrators</title>
  5. </head>
  6.  
  7. <body bgcolor="#FF9900" text="#FFFFCC" link="#FFFFFF" vlink="#FF3300" alink="#FFFF00">
  8.  
  9. <table width="1080">
  10.  
  11. <tr>
  12.  
  13.  
  14. <td width="710">
  15. <p>Search For Administrators
  16. <hr size="1"> <p/>
  17. <form action="admin_loggedin_search_admin.php" method="post">
  18. Search by :
  19. <select name="searchby">
  20. <option value="" SELECTED>-Select One-</option>
  21. <option value="name" >Name</option>
  22. <option value="state">State</option>
  23. <option value="username">Username</option>
  24. </select>
  25. <input type="text" name="query" size="10" maxlength="100" >
  26. <input type="submit" name="submit" value="submit">
  27. <?php
  28. $con = mysql_connect("localhost","root","");
  29. if(!$con)
  30. {
  31. die('Could not connect: ' . mysql_error());
  32. }
  33. mysql_select_db("polling",$con);
  34. $query1 = "SELECT * FROM administrator WHERE ".$_POST[searchby]." like '%".$_POST[query]."%'";
  35. $result = mysql_query($query1);
  36. //$result=mysql_query("SELECT * FROM administrator WHERE $_POST[searchby] LIKE '%$_POST[query]%'" );
  37. //$query1 = 'SELECT * FROM `administrator` WHERE `'.mysql_real_escape_string($_POST['searchby']).'` LIKE "%'.mysql_real_escape_string($_POST['query']).'%"';
  38. //mysql_query($query1) or die('SQL Syntax Error - query was: <u>'.$query.'</u><hr>'.mysql_error());
  39. $found=0;
  40. while($sri=mysql_fetch_array($result))
  41. {
  42. if($sri['name']!="")
  43. {
  44. $found++;
  45. echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;".$sri['name']."->".$sri['username'];
  46. }
  47. }
  48. if($found!=0)
  49. {echo "<br />Found ".$found." results!";}
  50.  
  51.  
  52. /*if(!mysql_query($sri,$con))
  53. {
  54.  die('Error: '.mysql_error());
  55. }*/
  56. mysql_close($con)
  57. ?>
  58.  
  59. <td width="270">
  60. <td width="170">
  61. <p>Search For
  62. <hr size="1">
  63. </p>
  64. <a href="admin_loggedin_search_voter.php" title="Search for Voters" >Voters</a>
  65. <p><a href="admin_loggedin_search_candidate.php" title="Search for Candidates" >Candidates</a></p>
  66. <p><a href="admin_loggedin_search_officer.php" title="Search for Officers" >Officers</a></p>
  67.  
  68. <tr/>
  69. </table>
  70. </body>
  71. </html>
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 7
Reputation: srinivasjinde is an unknown quantity at this point 
Solved Threads: 0
srinivasjinde srinivasjinde is offline Offline
Newbie Poster
 
-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
Last edited by srinivasjinde; 21 Days Ago at 12:58 pm.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,463
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 136
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Nearly a Posting Virtuoso
 
0
  #27
20 Days Ago
Try this:
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <title>Search for Administrators</title>
  5. </head>
  6.  
  7. <body bgcolor="#FF9900" text="#FFFFCC" link="#FFFFFF" vlink="#FF3300" alink="#FFFF00">
  8.  
  9. <table width="1080">
  10.  
  11. <tr>
  12.  
  13.  
  14. <td width="710">
  15. <p>Search For Administrators
  16. <hr size="1"> <p/>
  17. <form action="admin_loggedin_search_admin.php" method="post">
  18. Search by :
  19. <select name="searchby">
  20. <option value="" SELECTED>-Select One-</option>
  21. <option value="name" >Name</option>
  22. <option value="state">State</option>
  23. <option value="username">Username</option>
  24. </select>
  25. <input type="text" name="query" size="10" maxlength="100" >
  26. <input type="submit" name="submit" value="submit">
  27. <?php
  28. $con = mysql_connect("localhost","root","");
  29. if(!$con)
  30. {
  31. die('Could not connect: ' . mysql_error());
  32. }
  33. mysql_select_db("polling",$con);
  34. $query1 = 'SELECT * FROM `administrator` WHERE `'.mysql_real_escape_string($_POST['searchby']).'` LIKE "%'.mysql_real_escape_string($_POST['query']).'%"';
  35. mysql_query($query1) or die('SQL Syntax Error - query was: <u>'.$query.'</u><hr>'.mysql_error());
  36. $found=0;
  37. while($sri=mysql_fetch_array($result))
  38. {
  39. if($sri['name']!="")
  40. {
  41. $found++;
  42. echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;".$sri['name']."->".$sri['username'];
  43. }
  44. }
  45. if($found!=0)
  46. {echo "<br />Found ".$found." results!";}
  47.  
  48.  
  49. /*if(!mysql_query($sri,$con))
  50. {
  51.  die('Error: '.mysql_error());
  52. }*/
  53. mysql_close($con)
  54. ?>
  55.  
  56. <td width="270">
  57. <td width="170">
  58. <p>Search For
  59. <hr size="1">
  60. </p>
  61. <a href="admin_loggedin_search_voter.php" title="Search for Voters" >Voters</a>
  62. <p><a href="admin_loggedin_search_candidate.php" title="Search for Candidates" >Candidates</a></p>
  63. <p><a href="admin_loggedin_search_officer.php" title="Search for Officers" >Officers</a></p>
  64.  
  65. <tr/>
  66. </table>
  67. </body>
  68. </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
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 151
Reputation: venkat0904 is an unknown quantity at this point 
Solved Threads: 15
venkat0904's Avatar
venkat0904 venkat0904 is offline Offline
Junior Poster
 
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..

  1. if(!empty($_POST['searchby']) && !empty($_POST['query'])){
  2. $query1 = "SELECT * FROM user_tbl WHERE ".$_POST['searchby']." like '%".$_POST['query']."%'";
  3. $result = mysql_query($query1);
  4. $found=0;
  5.  
  6. while($sri=mysql_fetch_array($result))
  7. {
  8. if($sri['name']!="")
  9. {
  10. $found++;
  11. echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;".$sri['name']."->".$sri['username'];
  12. }
  13. }
  14. if($found!=0)
  15. {echo "<br />Found ".$found." results!";}
  16.  
  17. }

This should solve ur problem..
Cheers !!

Originally Posted by srinivasjinde View Post
now the search functionality has failed.....error:
SQL Syntax Error - query was:

Unknown column '' in 'where clause'


code is
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <title>Search for Administrators</title>
  5. </head>
  6.  
  7. <body bgcolor="#FF9900" text="#FFFFCC" link="#FFFFFF" vlink="#FF3300" alink="#FFFF00">
  8.  
  9. <table width="1080">
  10.  
  11. <tr>
  12.  
  13.  
  14. <td width="710">
  15. <p>Search For Administrators
  16. <hr size="1"> <p/>
  17. <form action="admin_loggedin_search_admin.php" method="post">
  18. Search by :
  19. <select name="searchby">
  20. <option value="" SELECTED>-Select One-</option>
  21. <option value="name" >Name</option>
  22. <option value="state">State</option>
  23. <option value="username">Username</option>
  24. </select>
  25. <input type="text" name="query" size="10" maxlength="100" >
  26. <input type="submit" name="submit" value="submit">
  27. <?php
  28. $con = mysql_connect("localhost","root","");
  29. if(!$con)
  30. {
  31. die('Could not connect: ' . mysql_error());
  32. }
  33. mysql_select_db("polling",$con);
  34. $query1 = "SELECT * FROM administrator WHERE ".$_POST[searchby]." like '%".$_POST[query]."%'";
  35. $result = mysql_query($query1);
  36. //$result=mysql_query("SELECT * FROM administrator WHERE $_POST[searchby] LIKE '%$_POST[query]%'" );
  37. //$query1 = 'SELECT * FROM `administrator` WHERE `'.mysql_real_escape_string($_POST['searchby']).'` LIKE "%'.mysql_real_escape_string($_POST['query']).'%"';
  38. //mysql_query($query1) or die('SQL Syntax Error - query was: <u>'.$query.'</u><hr>'.mysql_error());
  39. $found=0;
  40. while($sri=mysql_fetch_array($result))
  41. {
  42. if($sri['name']!="")
  43. {
  44. $found++;
  45. echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;".$sri['name']."->".$sri['username'];
  46. }
  47. }
  48. if($found!=0)
  49. {echo "<br />Found ".$found." results!";}
  50.  
  51.  
  52. /*if(!mysql_query($sri,$con))
  53. {
  54.  die('Error: '.mysql_error());
  55. }*/
  56. mysql_close($con)
  57. ?>
  58.  
  59. <td width="270">
  60. <td width="170">
  61. <p>Search For
  62. <hr size="1">
  63. </p>
  64. <a href="admin_loggedin_search_voter.php" title="Search for Voters" >Voters</a>
  65. <p><a href="admin_loggedin_search_candidate.php" title="Search for Candidates" >Candidates</a></p>
  66. <p><a href="admin_loggedin_search_officer.php" title="Search for Officers" >Officers</a></p>
  67.  
  68. <tr/>
  69. </table>
  70. </body>
  71. </html>
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!!
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 7
Reputation: srinivasjinde is an unknown quantity at this point 
Solved Threads: 0
srinivasjinde srinivasjinde is offline Offline
Newbie Poster
 
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 151
Reputation: venkat0904 is an unknown quantity at this point 
Solved Threads: 15
venkat0904's Avatar
venkat0904 venkat0904 is offline Offline
Junior Poster
 
0
  #30
18 Days Ago
kool... all well that ends well

Originally Posted by srinivasjinde View Post
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
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC