seanj43 Posted October 28, 2010 Share Posted October 28, 2010 Here is my code... <?php mysql_connect("localhost", "user", "pass")or die("cannot connect"); mysql_select_db("database")or die("cannot select DB"); $myemail = mysql_real_escape_string($_POST['myemail']); $mypassword = mysql_real_escape_string($_POST['mypassword']); $mypassword = md5($mypassword); $myemail = stripslashes($myemail); $mypassword = stripslashes($mypassword); $sql="SELECT * FROM users WHERE email='$myemail' and password='$mypassword'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1){ session_start(); $_SESSION["myemail"]= "$myemail"; header("location:home.php"); } else { header("location:fail.php"); } ?> What can I do to this code so that it will also store first name from the database inside a session? Quote Link to comment Share on other sites More sharing options...
revraz Posted October 28, 2010 Share Posted October 28, 2010 Move session_start to the first line after <?php $sql = "SELECT * FROM users WHERE email='$myemail' and password='$mypassword'"; $result = mysql_query($sql) or die ("Error in query: $sql. " . mysql_error()); //check rows if (mysql_num_rows($result) == 1) { $row = mysql_fetch_assoc($result); $_SESSION['ufname'] = $row ['ufname']; //this is your first name column name $_SESSION["myemail"]= "$myemail"; header("location:home.php"); } Quote Link to comment Share on other sites More sharing options...
seanj43 Posted October 28, 2010 Author Share Posted October 28, 2010 Thank you, perfect! Quote Link to comment 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.