I have a small script with PHP that queries a MySQL database to pull
out one row, where I want to be able to access each of the columns
separately. I have tried several different variations and am able to
get the entire row to print, but when I attempt to access the
individual columns I get an error. Here is what I have so far:
if (isset($_POST['memberNo'])):
$link = mysql_connect(' ...','...','... ');
mysql_select_db ("...");
//Perform a test query
$query = "SELECT * FROM users WHERE 'id' = " . $_POST['memberNo'];
$result = mysql_query($qu ery) or die(mysql_error ());
$line = mysql_fetch_ass oc($result);
print $line;
//Close connection
mysql_close($li nk);
The point of this code is to retrieve the user information to validate
the login information sent in the previous form. I do not get an
error with this code, but it also does not print anything. I know
there is an entry in the database that matches data sent in the
$_POST['memberNo'] variable, it is the only entry in the database.
Changing the 'print $line;' to 'print $line["id"];' does not display
anyting either.
Does anyone know where I am making the mistake? There should only be
one row returned and I want to be able to access the columns in that
row as an array.
Thanks for any information,
Wayne
out one row, where I want to be able to access each of the columns
separately. I have tried several different variations and am able to
get the entire row to print, but when I attempt to access the
individual columns I get an error. Here is what I have so far:
if (isset($_POST['memberNo'])):
$link = mysql_connect(' ...','...','... ');
mysql_select_db ("...");
//Perform a test query
$query = "SELECT * FROM users WHERE 'id' = " . $_POST['memberNo'];
$result = mysql_query($qu ery) or die(mysql_error ());
$line = mysql_fetch_ass oc($result);
print $line;
//Close connection
mysql_close($li nk);
The point of this code is to retrieve the user information to validate
the login information sent in the previous form. I do not get an
error with this code, but it also does not print anything. I know
there is an entry in the database that matches data sent in the
$_POST['memberNo'] variable, it is the only entry in the database.
Changing the 'print $line;' to 'print $line["id"];' does not display
anyting either.
Does anyone know where I am making the mistake? There should only be
one row returned and I want to be able to access the columns in that
row as an array.
Thanks for any information,
Wayne
Comment