fallenangel1983 Posted March 15, 2008 Share Posted March 15, 2008 Having loads of trouble integrating these session variables and have tried the online tutorials but i am having a specific problem. can you help please. I havea basic html form which allows users to enter a username and password. the next page is a php form and i use the following code: session_start(); mysql_connect blah blah mysql_select_db blah blah --now i have the following variables from the previous form: $username = $_POST['username']; $password = $_POST['password']; $_SESSION['username'] = $username; $_SESSION['password'] = $password; and now i start my sql to validate the data (which all works) it then (if info is correct) sends to a new page (which again all works). my problem is this. on the next page when i try to echo the username and password on the screen using this code: echo "{$_SESSION['username']} and {$_SESSION['password']} it returns the following statement: and bob (or hatever username i inserted) it remembers the username but the password. ive checked the code again and again and the username an password code is the same. can anyone help. will post more code if needed. just didnt want to flood the page with code. Quote Link to comment https://forums.phpfreaks.com/topic/96311-session-variables-s/ Share on other sites More sharing options...
discomatt Posted March 15, 2008 Share Posted March 15, 2008 my guess is a typo. Quote Link to comment https://forums.phpfreaks.com/topic/96311-session-variables-s/#findComment-492972 Share on other sites More sharing options...
Sulman Posted March 15, 2008 Share Posted March 15, 2008 can you post your code as it will help to find the problem. Ta. Quote Link to comment https://forums.phpfreaks.com/topic/96311-session-variables-s/#findComment-492973 Share on other sites More sharing options...
fallenangel1983 Posted March 15, 2008 Author Share Posted March 15, 2008 --HTML page <?php #LoginPage : LoginPage.php session_start(); ?> <html> <head> <title>Login Screen</title> </head> <body bgcolor="lightyellow"> <table width="100%" border="0"> <tr> <td><center><img src="img/Logo.jpg"></a></td> </tr> <tr></tr> <tr></tr> <tr></tr> <tr></tr> <tr> <td><center> <table width="300" border="1" align="center" cellpadding="1" cellspacing="1" bgcolor="black"> <tr> <form name="form1" method="post" action="CheckLogin.php"> <td> <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="cyan"> <tr> <td colspan="3"><strong><center> Member Login </strong></center></td> </tr> <tr> <td width="78">Username</td> <td width="6">:</td> <td width="294"><input name="username" type="username" id="username"></td> </tr> <tr> <td>Password</td> <td>:</td> <td><input name="password" type="password" id="password"></td> </tr> <tr> <td colspan="3"><center><input type="submit" name="Submit" value="Login"></center></td> </tr> </table> </td> </form> </tr> </table> </td> </tr> </table> </body> </html> --PHP page <?php session_start(); $db_name="project"; mysql_connect("localhost","root","") or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $username = $_POST['username']; $password = $_POST['password']; $_session['username'] = $username; $_session['password'] = $password; $sql="SELECT * FROM users WHERE username='$username' and password='$password'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1) { while($row=mysql_fetch_row($result)) { $username = $row[0]; $password = $row[1]; $idType = $row[2]; if($idType==1) { header("location:Users.php"); } elseif($idType==2) { header("location:Admin.php"); } elseif($idType==3) { header("location:Management.php"); } } } else { echo "Wrong Username or Password <br><a href='./LoginPage.php'>Go Back</a>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/96311-session-variables-s/#findComment-492975 Share on other sites More sharing options...
discomatt Posted March 15, 2008 Share Posted March 15, 2008 Variables in PHP are case-sensitive... you must refer to the session array as $_SESSION[ x ] Quote Link to comment https://forums.phpfreaks.com/topic/96311-session-variables-s/#findComment-492977 Share on other sites More sharing options...
fallenangel1983 Posted March 15, 2008 Author Share Posted March 15, 2008 Oh i thought that it was only user defined variables that were case sensitive. i assumed that $_SESSIOn was in in built function Quote Link to comment https://forums.phpfreaks.com/topic/96311-session-variables-s/#findComment-492979 Share on other sites More sharing options...
fallenangel1983 Posted March 15, 2008 Author Share Posted March 15, 2008 am i ok using session_start(); or do i have to use SESSION_START(); Quote Link to comment https://forums.phpfreaks.com/topic/96311-session-variables-s/#findComment-492980 Share on other sites More sharing options...
discomatt Posted March 15, 2008 Share Posted March 15, 2008 Functions are case-insensitive. $_SESSION is not a function, it's a superglobal array... read more here: http://php.net/variables.predefined Quote Link to comment https://forums.phpfreaks.com/topic/96311-session-variables-s/#findComment-492982 Share on other sites More sharing options...
fallenangel1983 Posted March 15, 2008 Author Share Posted March 15, 2008 brilliant. thanks a lot. ill try to implement it now and see what happens. cheers Quote Link to comment https://forums.phpfreaks.com/topic/96311-session-variables-s/#findComment-492989 Share on other sites More sharing options...
fallenangel1983 Posted March 15, 2008 Author Share Posted March 15, 2008 lol it was in lowercase in that one page so it didnt go through for the rest of it. the entire thing works now. greatly appreciate it. thanks again Quote Link to comment https://forums.phpfreaks.com/topic/96311-session-variables-s/#findComment-492996 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.