mysql - Cant retrieve data from an SQL database using PHP and session variables -


i have website following code in header - php echos in body returning anything:

<?php session_start(); print_r($_session);  $user = $_session['email']; $query = "select * first_page_data 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 session variable named 'email' receiving value previous page print_r function on line 3. variable $user getting correct email address.

the database set correctly (ive been able access in other ways, im trying modify access data related particular email address shown).

if point me in right direction id apprectiate it! side, how people suggest debugging php other littering code echos , print_r functions? there way put breakpoints in example?


edited in answer below

as requested, code 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 * first_page_data email_address= '$user' ";  $result = mysql_query($query, $first_data);  $row_buyerdetails = mysql_fetch_assoc($result);  print_r($row_buyerdetails);  ?> 

aren't missing mysql_connect call in header or includes?

try adding:

echo mysql_errno($link) . ": " . mysql_error($link). "\n"; 

$link being resource mysql_connect.

to debug php have install or activate extension called xdebug , use nice ide phpstorm, bob's uncle :)

you can use zend debugger have limited experience it.

you can (and should) have full error reporting on when developing. tell example mysql_* functions deprecated.

if not want errors appear on page, can choose write log file , keep tail open on file.

update code:

<?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); mysql_select_db($database_first_data, $first_data);  session_start();  print_r($_session); $user = $_session['email']; echo $user; $query = "select * first_page_data email_address= '$user' ";  $result = mysql_query($query, $first_data);  echo mysql_errno($first_data) . ": " . mysql_error($first_data). "\n";  $row_buyerdetails = mysql_fetch_assoc($result);  print_r($row_buyerdetails);  ?> 

tell me version outputs...


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -