I am trying to create a login script. I am having a problem though when trying to select certain fields from a database and then output them.
Here is the part of the code which is causing the problem.
$query = "SELECT customerid, firstname, lastname FROM customers WHERE username='".$_REQUEST['username']."' AND userpass='".$_REQUEST['password']."'";
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
if($num_rows != 1) {
echo("That username and password does not exist in our database. Please go back and try again.");
exit;
}
if($num_rows = 1) {
session_start();
$_SESSION['customerid'] = mysql_result($result,"customerid");
$_SESSION['firstname'] = mysql_result($result,"firstname");
$_SESSION['lastname'] = mysql_result($result,"lastname");
header( "Location: /testpage.php" );
} else {
echo("That username and password does not exist in our database. Please go back and try again.");
}
For some reason when I try and echo my information like say $SESSION['firstname'] and $SESSION['lastname'] both of their values will just be the same as the customerid value. Which is not correct. Whichever field comes first in the query like customerid is first, the other two fields use the value of that first one. Which is not correct. Why is it doing this?
Thanks