I have a website with the following code in the header - but the PHP echos in the body are returning anything:
<?php
session_start();
print_r($_SESSION);
$user = $_SESSION['email'];
$query = "SELECT * FROM first_page_data WHERE email_address= '$user' ";
$result = mysql_query($query);
$row_buyerdetails = mysql_fetch_assoc($result);
?>
The following returns nothing:
<?php echo $row_buyerdetails['phone_number'] ?>
I know the session variable named 'email' is receiving a value from the previous page from the print_r function on line 3. Variable $user is also getting the correct email address.
The database is set up correctly (ive been able to access successfully in other ways, but im trying to modify it to access the data related to a particular email address as shown).
If somebody could point me in the right direction id apprectiate it! Also as a side, how would people suggest debugging PHP other than littering the code with echos and print_r functions? Is there even a way to put breakpoints in for example?
EDITED FOR HELP IN THE ANSWER BELOW
As requested, this is the code with the alterations requested:
<?php
$hostname_first_data = "*****";
$database_first_data = "*****";
$username_first_data = "*****";
$password_first_data = "*****";
$first_data = mysql_pconnect($hostname_first_data, $username_first_data, $password_first_data) or trigger_error(mysql_error(),E_USER_ERROR);
echo mysql_errno($first_data) . ": " . mysql_error($first_data). "\n";
session_start();
print_r($_SESSION);
$user = $_SESSION['email'];
echo $user;
$query = "SELECT * FROM first_page_data WHERE email_address= '$user' ";
$result = mysql_query($query, $first_data);
$row_buyerdetails = mysql_fetch_assoc($result);
print_r($row_buyerdetails);
?>