Jump to content

Storing MySql data in a session


Recommended Posts

Here is my code...


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'";


$_SESSION["myemail"]= "$myemail"; 
else {


What can I do to this code so that it will also store first name from the database inside a session?


Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.