Jump to content

Having trouble searching database with this code


pioneerx01

Recommended Posts

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>

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.