Vamshi King Vamshi King - 2 months ago 4x
PHP Question

cannot use values of session variables in another page

I created a session in my index page AKA login page, when i'm trying to use that value in select query in another page it doesnot work can any one help me.enter image description here

enter image description here


$connection = mysql_connect('localhost','root','root') or die ("Couldn't connect to server.");
$db = mysql_select_db('test', $connection) or die ("Couldn't select database.");

$data ="select user_id,first_name,last_name,father_name,address,pincode,dob,phone from acc where user_id='" .$_SESSION['userSession']. "'";
$query = mysql_query($data) or die("Couldn't execute query. ". mysql_error());
$data2 = mysql_fetch_array($query);


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"


<!-- form to display record from database -->
<form name="form" method="POST" action="abcd2.php">
first Name: <input type="text" name="firstname" value="<?php echo $data2 ['first_name']?>"/> <br>
last Name : <input type="text" name="lastname" value="<?php echo $data2 ['last_name']?>"/> <br>
father Name: <input type="text" name="fathername" value="<?php echo $data2 ['father_name']?>"/> <br>
address: <input type="text" name="address" value="<?php echo $data2 ['address']?>"/> <br>
pincode: <input type="text" name="pincode" value="<?php echo $data2 ['pincode']?>"/> <br>
DOB: <input type="text" name="dob" value="<?php echo $data2 ['dob']?>"/><br>
phone: <input type="text" name="phone" value="<?php echo $data2 ['phone']?>"/> <br>
<input type="submit" value="submit">




Please stop using mysql_* (Deprecated from php5.5 onward and removed from php7).

Use mysqli_* OR PDO with prepared statement (To prevent from SQL Injection).


Add session_start(); on top of each php page just after starting <?php to make SESSION variables available on that page