I've been building a client log-in system recently, and I've managed to get ther user to register and then sign in successfully. Now with multiple users, Im trying to re-direct a different user to a different page.
The full page of code im working with is the following;
Code: Select all
<?php
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name=""; // 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
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
$_SESSION['myusername'] = $myusername;
$_SESSION['mypassword'] = $mypassword;
if($myusername = "john") $url = "page1.php";
else
if($myusername = "adam") $url = "page2.php";
header("location: ".$url);
}
else {
echo "Wrong Username or Password";
}
?>
Code: Select all
$_SESSION['myusername'] = $myusername;
$_SESSION['mypassword'] = $mypassword;
if($myusername = "john") $url = "page1.php";
else
if($myusername = "adam") $url = "page2.php";
header("location: ".$url);
I tried using the unset variable function in between them but then that just sent both users to page2.php
What I want is for when john signs in he gets sent to page1.php and when adam signs in he gets sent to page2.php.
Does anyone have any ideas where I'm going wrong here?
Thanks,
Jerry