943,965 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 114970
  • PHP RSS
You are currently viewing page 3 of this multi-page discussion thread; Jump to the first page
Nov 8th, 2009
0
Re: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
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...

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...
Reputation Points: 13
Solved Threads: 21
Junior Poster
venkat0904 is offline Offline
186 posts
since Oct 2009
Nov 8th, 2009
-1
Re: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
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
Reputation Points: 10
Solved Threads: 0
Light Poster
srinivasjinde is offline Offline
29 posts
since Nov 2009
Nov 8th, 2009
0
Re: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
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

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
Reputation Points: 13
Solved Threads: 21
Junior Poster
venkat0904 is offline Offline
186 posts
since Oct 2009
Nov 8th, 2009
0
Re: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
Try this.
php Syntax (Toggle Plain Text)
  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; Nov 8th, 2009 at 8:04 am. Reason: bugs
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,004 posts
since Sep 2007
Nov 8th, 2009
-1
Re: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
now the search functionality has failed.....error:
SQL Syntax Error - query was:

Unknown column '' in 'where clause'


code is
PHP Syntax (Toggle Plain Text)
  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>
Reputation Points: 10
Solved Threads: 0
Light Poster
srinivasjinde is offline Offline
29 posts
since Nov 2009
Nov 8th, 2009
-1
Re: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
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; Nov 8th, 2009 at 12:58 pm.
Reputation Points: 10
Solved Threads: 0
Light Poster
srinivasjinde is offline Offline
29 posts
since Nov 2009
Nov 8th, 2009
0
Re: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
Try this:
php Syntax (Toggle Plain Text)
  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>
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,004 posts
since Sep 2007
Nov 9th, 2009
1
Re: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
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..

PHP Syntax (Toggle Plain Text)
  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 !!

now the search functionality has failed.....error:
SQL Syntax Error - query was:

Unknown column '' in 'where clause'


code is
PHP Syntax (Toggle Plain Text)
  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; Nov 9th, 2009 at 2:45 am.
Reputation Points: 13
Solved Threads: 21
Junior Poster
venkat0904 is offline Offline
186 posts
since Oct 2009
Nov 10th, 2009
0
Re: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
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.
Reputation Points: 10
Solved Threads: 0
Light Poster
srinivasjinde is offline Offline
29 posts
since Nov 2009
Nov 11th, 2009
0
Re: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
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.
Reputation Points: 13
Solved Threads: 21
Junior Poster
venkat0904 is offline Offline
186 posts
since Oct 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: SMTP limitation?
Next Thread in PHP Forum Timeline: Please Help...New to MySQL





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC