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

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

$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
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

 

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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