jnerotrix Posted December 7, 2008 Share Posted December 7, 2008 Error i Get: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home3/sex1800/public_html/demos/search/search.php on line 13 Heres the code <?php $hostname_php_result_conn = "localhost"; $database_php_result_conn = "sex1800_phpresult"; $username_php_result_conn = "sex1800_demo"; $password_php_result_conn = "demotable"; $php_result_conn = mysql_connect($hostname_php_result_conn, $username_php_result_conn, $password_php_result_conn); mysql_select_db($database_php_result_conn,$php_result_conn); if(isset($_POST['submit'])) { $roll_no = $_POST['roll_no']; $sql = mysql_query("SELECT * FROM result_table WHERE roll_no = $roll_no"); $row1 = mysql_fetch_array($sql); $name = $row1['name']; $marks = $row1['marks']; if($row1 == 0) { echo 'Error, ID does not exist'; } else { echo 'Name = '.$name.'<br /> Marks = '.$marks; } } else { ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <style type="text/css"> #header { width:100%; background:lightblue; margin:0px; padding:0px; } #leftbar { float:left; width:40%; height:30px; background:lightblue; text-align:right; } #rightbar { float:left; width:60%; height:30px; background:lightblue; text-align:center; } #bar { width:100%; background:lightblue; } #center {float:center; width:60%; height:10px; background:lightblue; align:center; } a { font-family:Arial; font-size:16px; background-color:aqua; color:blue; font-weight:bold; vertical-align:text-bottom; } a:hover { font-family:Lucida Calligraphy; font-size:ahoversize1; background-color:yellow; color:darkblue; } </style> </head> <center> <body> <br><Br><Br> <h1> Search Roll Number </h1> <Br><br> <div id="header"> <div id="center"> <table> <form action="search.php" method="post"> <tr> <td>Roll Number:</td><td><input name="roll_no" type="text" id="roll_no" /></td> </tr> <tr> <td align="center"><input type="submit" name="submit" value="search" /></td> </tr> </form> </table> </div> <div id="leftbar"> </div> <div id="rightbar"> </div> </div> <div id="bar"> </div> <div id="header"> <div id="leftbar"> </div> <div id="rightbar"> </div> </div> </body> </html> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/135934-solved-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-resource/ Share on other sites More sharing options...
MatthewJ Posted December 7, 2008 Share Posted December 7, 2008 $sql = mysql_query("SELECT * FROM result_table WHERE roll_no = $roll_no") or die (mysql_error()); May shed some light on the issue. You could also do the same for the db selection and connection if the query looks okay. Link to comment https://forums.phpfreaks.com/topic/135934-solved-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-resource/#findComment-708578 Share on other sites More sharing options...
jnerotrix Posted December 7, 2008 Author Share Posted December 7, 2008 Now it Just Says "No database selected" ---------- Heres The Code: Added Your Line and error_reporting(E_ALL); <?php error_reporting(E_ALL); $hostname_php_result_conn = "localhost"; $database_php_result_conn = "sex1800_phpresult"; $username_php_result_conn = "sex1800_demo"; $password_php_result_conn = "demotable"; $php_result_conn = mysql_connect($hostname_php_result_conn, $username_php_result_conn, $password_php_result_conn); mysql_select_db($database_php_result_conn,$php_result_conn); if(isset($_POST['submit'])) { $roll_no = $_POST['roll_no']; $sql = mysql_query("SELECT * FROM result_table WHERE roll_no = $roll_no") or die (mysql_error()); $row1 = mysql_fetch_array($sql); $name = $row1['name']; $marks = $row1['marks']; if($row1 == 0) { echo 'Error, ID does not exist'; } else { echo 'Name = '.$name.'<br /> Marks = '.$marks; } } else { ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <style type="text/css"> #header { width:100%; background:lightblue; margin:0px; padding:0px; } #leftbar { float:left; width:40%; height:30px; background:lightblue; text-align:right; } #rightbar { float:left; width:60%; height:30px; background:lightblue; text-align:center; } #bar { width:100%; background:lightblue; } #center {float:center; width:60%; height:10px; background:lightblue; align:center; } a { font-family:Arial; font-size:16px; background-color:aqua; color:blue; font-weight:bold; vertical-align:text-bottom; } a:hover { font-family:Lucida Calligraphy; font-size:ahoversize1; background-color:yellow; color:darkblue; } </style> </head> <center> <body> <br><Br><Br> <h1> Search Roll Number </h1> <Br><br> <div id="header"> <div id="center"> <table> <form action="search.php" method="post"> <tr> <td>Roll Number:</td><td><input name="roll_no" type="text" id="roll_no" /></td> </tr> <tr> <td align="center"><input type="submit" name="submit" value="search" /></td> </tr> </form> </table> </div> <div id="leftbar"> </div> <div id="rightbar"> </div> </div> <div id="bar"> </div> <div id="header"> <div id="leftbar"> </div> <div id="rightbar"> </div> </div> </body> </html> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/135934-solved-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-resource/#findComment-708581 Share on other sites More sharing options...
jnerotrix Posted December 7, 2008 Author Share Posted December 7, 2008 Heres the page http://1800sexnow.com/demos/search/search.php type in a number and click search Link to comment https://forums.phpfreaks.com/topic/135934-solved-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-resource/#findComment-708586 Share on other sites More sharing options...
jnerotrix Posted December 7, 2008 Author Share Posted December 7, 2008 I have changed the code i added some javascript thats all it disallows users to type text only numbers in form field heres the new code but i still get the same error <?php error_reporting(E_ALL); $hostname_php_result_conn = "localhost"; $database_php_result_conn = "sex1800_phpresult"; $username_php_result_conn = "sex1800_demo"; $password_php_result_conn = "demotable"; $php_result_conn = mysql_connect($hostname_php_result_conn, $username_php_result_conn, $password_php_result_conn); mysql_select_db($database_php_result_conn,$php_result_conn); if(isset($_POST['submit'])) { $roll_no = $_POST['roll_no']; $sql = mysql_query("SELECT * FROM result_table WHERE roll_no = $roll_no") or die (mysql_error()); $row1 = mysql_fetch_array($sql); $name = $row1['name']; $marks = $row1['marks']; if($row1 == 0) { echo 'Error, ID does not exist'; } else { echo 'Name = '.$name.'<br /> Marks = '.$marks; } } else { ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <style type="text/css"> #header { width:100%; background:lightblue; margin:0px; padding:0px; } #leftbar { float:left; width:40%; height:30px; background:lightblue; text-align:right; } #rightbar { float:left; width:60%; height:30px; background:lightblue; text-align:center; } #bar { width:100%; background:lightblue; } #center {float:center; width:60%; height:10px; background:lightblue; align:center; } a { font-family:Arial; font-size:16px; background-color:aqua; color:blue; font-weight:bold; vertical-align:text-bottom; } a:hover { font-family:Lucida Calligraphy; font-size:ahoversize1; background-color:yellow; color:darkblue; } </style> <script type="text/javascript"> function numbersonly(myfield, e, dec) { var key; var keychar; if (window.event) key = window.event.keyCode; else if (e) key = e.which; else return true; keychar = String.fromCharCode(key); // control keys if ((key==null) || (key==0) || (key== || (key==9) || (key==13) || (key==27) ) return true; // numbers else if ((("0123456789").indexOf(keychar) > -1)) return true; // decimal point jump else if (dec && (keychar == ".")) { myfield.form.elements[dec].focus(); return false; } else return false; } </script> </head> <center> <body> <br><Br><Br> <h1> Search Roll Number </h1> <Br><br> <div id="header"> <div id="center"> <table> <form action="search.php" method="post"> <tr> <td>Roll Number:</td><td><input name="roll_no" type="text" id="roll_no" onkeypress="return numbersonly(this, event)" /></td> </tr> <tr> <td align="center"><input type="submit" name="submit" value="search" /></td> </tr> </form> </table> </div> <div id="leftbar"> </div> <div id="rightbar"> </div> </div> <div id="bar"> </div> <div id="header"> <div id="leftbar"> </div> <div id="rightbar"> </div> </div> </body> </html> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/135934-solved-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-resource/#findComment-708590 Share on other sites More sharing options...
premiso Posted December 7, 2008 Share Posted December 7, 2008 Are you sure you have a database called sex1800_phpresult ? Link to comment https://forums.phpfreaks.com/topic/135934-solved-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-resource/#findComment-708593 Share on other sites More sharing options...
jnerotrix Posted December 7, 2008 Author Share Posted December 7, 2008 i feel stupid i mistyped the database name is sex1800_phpresults Link to comment https://forums.phpfreaks.com/topic/135934-solved-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-resource/#findComment-708595 Share on other sites More sharing options...
Philip Posted December 7, 2008 Share Posted December 7, 2008 Also, make sure an ID was input, otherwise instead of a nice error message they'll get this mess: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 Link to comment https://forums.phpfreaks.com/topic/135934-solved-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-resource/#findComment-708596 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.