I'm currently working on getting a login working for a business site. On my first php file that checks the username and password with the database, everything seems to be working correctly. The print out reads the right information. However, when I try to pass the variables (myusername, mypassword, and myadminlevel) to the next page (login_success.php), it gives me the error "Notice: Undefined index: myuserlevel in C:\wamp\www\wordpress\wordpress\wp-content\themes\skyline\login_success.php on line 3" for all variables. I am currently using $_SESSION to pass the variables, but I have tried session_register and got a different error message! If someone could help me out, it would be much appreciated!
Here is the code for the first page (please excuse the mess, I've been experimenting with it for a while):
<?php
$host="localhost"; // Host name
$username="user"; // Mysql username
$password="pass"; // Mysql password
$db_name="454368_mbtn"; // Database name
$tbl_name="mm_users"; // 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 UserId='$myusername' and UserPassword='$mypassword'";
$result=mysql_query($sql);
$row = mysql_fetch_assoc($result);
// 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){
// Make variables global
$_SESSION["myuserlevel"] = $row['AdminLevel'];
$_SESSION["myusername"] = $row['UserId'];
$_SESSION["mypassword"] = $row['UserPassword'];
echo $_SESSION["myusername"];
echo $_SESSION["mypassword"];
echo $_SESSION["myuserlevel"];
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>
Here is the code for the second page:
<?php
session_start();
echo $_SESSION["myuserlevel"];
echo $_SESSION["myusername"];
echo $_SESSION["mypassword"];
?>
Thanks!