Jump to content

mysql_fetch_array ERROR ?


plodos

Recommended Posts

$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 ?

Link to comment
https://forums.phpfreaks.com/topic/107064-mysql_fetch_array-error/
Share on other sites

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 ...

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 ?

'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.

$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 ?

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.

$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...

 

 

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?

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.