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? Link to comment https://forums.phpfreaks.com/topic/217116-storing-mysql-data-in-a-session/ 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"); } Link to comment https://forums.phpfreaks.com/topic/217116-storing-mysql-data-in-a-session/#findComment-1127627 Share on other sites More sharing options...
seanj43 Posted October 28, 2010 Author Share Posted October 28, 2010 Thank you, perfect! Link to comment https://forums.phpfreaks.com/topic/217116-storing-mysql-data-in-a-session/#findComment-1127634 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.