Basically when a user on my site is logging in it sends username and password and comes to this page, im trying to make this page get there userid from the members table and carry it over with a session which will be user id, ive got on the index a 'echo' to show the userid and the username, the username shows fine but the userid does not... Now could anyone help me why this is not retrieving the userid or not starting the session :S HELP please
<?php
session_start();
$host=""; // Host name
$username="lands"; // Mysql username
$password=""; // Mysql password
$db_name="lands"; // Database name
$tbl_name="members"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from form
$username=$_POST['username'];
$password=$_POST['password'];
// To protect MySQL injection (more detail about MySQL injection)
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$sql="SELECT userid FROM $tbl_name WHERE username='$username' and password='$password'";
$result=mysql_query($sql);
while($row = mysql_fetch_array($result))
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $username and $password, table row must be 1 row
if($count==1){
// Register $username, $password and redirect to file "login_success.php"
session_register("username");
session_register("password");
$_SESSION['userid']=$row['userid'];
$_SESSION['username']=$username;
header("location:login_success.php");
}
else {
echo "
<table width='100%' height='100%' border='1' bgcolor='#657383'><tr><td valign='center' align='center'>
<font size='5' color='#ffffff' face='arial'>
Incorrect Details Please <a href='LINK TO HOME'><font size='5' color='#ffffff' face='arial'>Try Again</font></a>
</font>
</td></tr></table>";
}
?>
THANKSS.....