pioneerx01 Posted December 12, 2010 Share Posted December 12, 2010 Hello, I have this code running and I keep getting "Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/.../search.php on line 10 Any help would be appreciated <table><tr><td>ID</td><td>SCHOOL NAME</td><td>TEACHER NAME</td></tr> <?php if(isset($_POST['submit'])){ if(isset($_GET['go'])){ if(preg_match("/^[ a-zA-Z]+/", $_POST['name'])){ $name=$_POST['name']; $db=mysql_connect ("", "", "") or die ('I cannot connect to the database because: ' . mysql_error()); $mydb=mysql_select_db(""); $sql="SELECT ID, school_name, teacher_name FROM Project_Registration WHERE school_name LIKE '%" . $name . "%'"; $result=mysql_query($sql); while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ echo "<tr><td> {$row['ID']} </td>" . "<td> {$row['school_name']} </td>" . "<td> {$row['teacher_name']} </td></tr>";}}}} ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/221371-having-trouble-searching-database-with-this-code/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 12, 2010 Share Posted December 12, 2010 If you search for that error message you will find that it most commonly means that your query failed due to an error. If you echo mysql_error(); on the next line after the line with the mysql_query() statement, it will tell you why the query failed. Quote Link to comment https://forums.phpfreaks.com/topic/221371-having-trouble-searching-database-with-this-code/#findComment-1146064 Share on other sites More sharing options...
pioneerx01 Posted December 12, 2010 Author Share Posted December 12, 2010 oh, i have misspelled the table name. Nice trick with "echo mysql_error();" I did not know that one. Thanks a lot. Quote Link to comment https://forums.phpfreaks.com/topic/221371-having-trouble-searching-database-with-this-code/#findComment-1146066 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.