Jump to content

$_SESSION porblem


Sharkadder

Recommended Posts

Hi, on my website i am using $_SESSION variable, now i am new to how this works but basically this is what i am trying to do.If a database has a value in then it displays the row from that database, if the database doesn't have a value in, i'd like to display the text "you don't have any subscriptions"I have been trying this the last hour and cannot get it working right, here is my current code:$dbHost = '********.net';// Database Connection Details - Host$dbUser = 'dream*****';// Database Connection Details - Username$dbPass = '********';// Database Connection Details - Password$dbname = '******';// Database Connection Details - Database Name$db = mysql_connect($dbHost,$dbUser,$dbPass); // Connection Codemysql_select_db($dbname,$db); // Connects to database$query = "SELECT Username, Boxtype, Sublength, Subleft, Startdate, Expirydate FROM satellitebox WHERE Username = '$username'";$result = mysql_query($query, $db);SESSION_START();$_SESSION['displaydata'] = 1;if(mysql_num_rows($result)){$row = mysql_fetch_assoc($result);$newline = "<br />";// If the login information is correct do the following;echo "Username : {$row[username]} ".$newline;echo "Box Type : {$row[boxtype]} ".$newline ;echo "Subscription Length : {$row[sublength]} ".$newline ;echo "Subsciption Length Remaining : {$row[subleft]} ".$newline ;echo "Start Date : {$row[startdate]} ".$newline ;echo "Expiry Date : {$row[Expirydate]} ".$newline ;}else{ $_SESSION['displaydata'] = 'you currently have no subscriptions'; echo $SESSION['displaydata'];}ok i have commented out the server details but in the live version i have they are included so that isn't the problem, why is it then when i do the database lookup and they isn't a record with the $username variable i cannot display the text "you currently have no subscriptions"?, but yet if the $username variable is in the database, it will display all the frields relating to that record.thanks

Link to comment
Share on other sites

$_SESSION['displaydata'] =echo $SESSION['displaydata'];Why are you even using the session at all though? The session is for saving data across several pages, you don't need to use the session for data on a single page.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...