plodos Posted May 24, 2008 Share Posted May 24, 2008 $name = $HTTP_POST_VARS['name']; $surname = $HTTP_SERVER_VARS['surname']; $query = "select * from patient where pt_name like '%".$name."%' AND pt_surname like '%".$surname."%' "; Print "<table border cellpadding=1>"; $data = mysql_query($query); while($info=mysql_fetch_array($data)) { Print "<tr>"; Print "<th>Patient ID:</th> <td>{$info['pt_id']}</td> "; Print "<th>Name:</th> <td>{$info['pt_name']}</td> "; Print "<th>Surname:</th> <td>{$info['pt_surname']}</td> "; Print "<th>SSN:</th> <td>{$info['pt_SSN']}</td> "; Print "<th>Add:</th> <td>{$info['pt_add']} </td>"; Print "<th>Tel:</th> <td>{$info['pt_tel']} </td>"; Print "<th>Blood:</th> <td>{$info['pt_blood']} </td>"; Print "<th>Visit Date:</th> <td>{$info['pt_visit']} </td>"; echo "<td><a href=\"_edit.php?id=".$info['pt_id']."\"> EDIT </a>"; Print"</tr>"; } Print "</table>"; it gives an error like mysql_fetch_array() supplied ..... why ? Quote Link to comment https://forums.phpfreaks.com/topic/107064-mysql_fetch_array-error/ Share on other sites More sharing options...
AndyB Posted May 24, 2008 Share Posted May 24, 2008 change $data = mysql_query($query); to $data = mysql_query($query) or die("Error ". mysql_error(). " with query ". $query); If the fix to your problem isn't then obvious, post the error message here. Presumably, elsewhere in your code ahead of the query you make the database connection and select the database ... Quote Link to comment https://forums.phpfreaks.com/topic/107064-mysql_fetch_array-error/#findComment-548852 Share on other sites More sharing options...
plodos Posted May 24, 2008 Author Share Posted May 24, 2008 if I write this sentence select * from patient where pt_name like '%laura%' AND pt_surname like '%sams%' php script is working... but if I write $name = $HTTP_POST_VARS['name']; $surname = $HTTP_POST_VARS['surname']; $name = addslashes($name); $surname = addslashes($surname); $query = "select * from patient where pt_name like '%".$name."%' AND pt_surname like '%".$surname."%' "; page shows nothing...why ? Quote Link to comment https://forums.phpfreaks.com/topic/107064-mysql_fetch_array-error/#findComment-548866 Share on other sites More sharing options...
AndyB Posted May 24, 2008 Share Posted May 24, 2008 'page shows nothing' - do you mean you see a completely blank screen or that you see the expected output but with no data/results displayed? If a querystring isn't returning what you expect, add a line to echo the query to see exactly what it says - which may not be what you think it should be. And HTTP_POST_VARS is deprecated. Use $_POST['varname'] instead. Quote Link to comment https://forums.phpfreaks.com/topic/107064-mysql_fetch_array-error/#findComment-548874 Share on other sites More sharing options...
plodos Posted May 24, 2008 Author Share Posted May 24, 2008 $name = $HTTP_POST_VARS['name']; $surname = $HTTP_SERVER_VARS['surname']; $query = "select * from patient where pt_name like '%".$name."%' AND pt_surname like '%".$surname."%' "; Print "<table border cellpadding=1>"; $data = mysql_query($query); while($info=mysql_fetch_array($data)) { Print "<tr>"; Print "<th>Patient ID:</th> <td>{$info['pt_id']}</td> "; Print "<th>Name:</th> <td>{$info['pt_name']}</td> "; Print "<th>Surname:</th> <td>{$info['pt_surname']}</td> "; Print "<th>SSN:</th> <td>{$info['pt_SSN']}</td> "; Print "<th>Add:</th> <td>{$info['pt_add']} </td>"; Print "<th>Tel:</th> <td>{$info['pt_tel']} </td>"; Print "<th>Blood:</th> <td>{$info['pt_blood']} </td>"; Print "<th>Visit Date:</th> <td>{$info['pt_visit']} </td>"; echo "<td><a href=\"_edit.php?id=".$info['pt_id']."\"> EDIT </a>"; Print"</tr>"; } Print "</table>"; it gives an error like mysql_fetch_array() supplied ..... why ? Quote Link to comment https://forums.phpfreaks.com/topic/107064-mysql_fetch_array-error/#findComment-548901 Share on other sites More sharing options...
AndyB Posted May 24, 2008 Share Posted May 24, 2008 I'll try again. change $query = "select * from patient where pt_name like '%".$name."%' AND pt_surname like '%".$surname."%' "; Print "<table border cellpadding=1>"; $data = mysql_query($query); to $query = "select * from patient where pt_name like '%".$name."%' AND pt_surname like '%".$surname."%' "; echo $query; // new line Print "<table border cellpadding=1>"; $data = mysql_query($query) or die("Error ". mysql_error(). " with query ". $query); // modified line Post EXACTLY what the echo $query line generates. Post EXACTLY the full error message that's generated. Quote Link to comment https://forums.phpfreaks.com/topic/107064-mysql_fetch_array-error/#findComment-548906 Share on other sites More sharing options...
plodos Posted May 24, 2008 Author Share Posted May 24, 2008 $query = "select * from patient where pt_name like '%".$name."%' AND pt_surname like '%".$surname."%' "; I delete this line AND pt_surname like '%".$surname."%' now, the script is working correctly but only searching the name but $query = "select * from patient where pt_name like '%".$name."%' AND pt_surname like '%".$surname."%' "; echo $query; // new line output like that select * from patient where pt_name=laura AND pt_surname= surname is blank... Quote Link to comment https://forums.phpfreaks.com/topic/107064-mysql_fetch_array-error/#findComment-548928 Share on other sites More sharing options...
AndyB Posted May 24, 2008 Share Posted May 24, 2008 output like that select * from patient where pt_name=laura AND pt_surname= surname is blank... Then we now know that $surname is not being retrieved from the POSTed data. Maybe surname is not the field name in your form; maybe there's an error in your form post array retrieval code; maybe ... Who knows? Quote Link to comment https://forums.phpfreaks.com/topic/107064-mysql_fetch_array-error/#findComment-548930 Share on other sites More sharing options...
.josh Posted May 24, 2008 Share Posted May 24, 2008 repost your code as it stands right now with the changes Quote Link to comment https://forums.phpfreaks.com/topic/107064-mysql_fetch_array-error/#findComment-548932 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.