tags:

views:

23

answers:

3

i am trying to implement an extract function to grab data from my database and display it in a form so i cn update the database. the form is ok but the extract function.. this is what i have:

$id = $_GET['id'];

$qP = "SELECT * FROM test_mysql WHERE id = '$id'  ";
$rsP = mysql_query($qP);
$row = mysql_fetch_array($rsP);
extract($row);
$fullname = trim($fullname);
$dob = trim($dob);
$time = trim($time);

but its telling me:

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given

and

Warning: extract() expects parameter 1 to be array, null given

thing is the code is working fine in ConTEXT but giving that error in dremweaver. what could be the problem?

+1  A: 

You most probably have an error with MySQL. Try this:

$rsP = mysql_query($qP) or die(mysql_error());

This will tell you if something goes wrong with your query.

Some possible errors I can think of right away that you should investigate:

  • Do you have a connection to the database (using mysql_connect)?
  • Do the table test_mysql exist?
  • Is $_GET['id'] a number or a string? If it is a number, the end of your query should be changed to id = $id
Emil Vikström
A: 

This is likely due to a return value of false from the database (or lack thereof).

Orbit
A: 

As specified in PHP manual,

mysql_query() returns a resource on success, or FALSE on error.

So, looks like there's problem in query. You may look at error message and continue problem investigation:

$qP = "SELECT * FROM test_mysql WHERE id = '$id'  ";
$rsP = mysql_query($qP);
echo mysql_error();
Kel