JoelRocks Posted August 24, 2007 Share Posted August 24, 2007 Despite help, still having issues with this code, can anyone help me... Gives an error i think its the SQL PHP functions... <?php $hostname= "localhost"; $user= "remotepa_framewo"; $password = "-"; $conn = @mysql_connect( $hostname, $user, $password ) or die ("Could not connect to server"); $db = @mysql_select_db("remotepa_framework", $conn) or die ("Could not connect to database"); $sql = "SELECT * FROM users WHERE username=\"$_SESSION['username']\""; $result = @mysql_query( $sql, $conn) or die ("Could not execute query"); $output = mysql_fetch_assoc($sql); session_start(); session_id($_GET['PHPSESSID']);//set php session id from URL if(isset($_SESSION['username'])) { if($output['active'] < 1) { echo ("Please reset your details"); echo ("Hello " .$_SESSION['username']); echo ("<br />"); echo ("You are logged in successfully"); } } else { echo ("Sorry you are not logged in"); exit; } ?> Link to comment https://forums.phpfreaks.com/topic/66545-solved-problems-with-indexphp-code/ Share on other sites More sharing options...
lemmin Posted August 24, 2007 Share Posted August 24, 2007 Though it is best if you post the error so people know what to look for, I don't think you should be using double quotes in the sql query. Change: $sql = "SELECT * FROM users WHERE username=\"$_SESSION['username']\""; [code] to: [code] $sql = "SELECT * FROM users WHERE username='$_SESSION['username']'"; [/code][/code] Link to comment https://forums.phpfreaks.com/topic/66545-solved-problems-with-indexphp-code/#findComment-333269 Share on other sites More sharing options...
JoelRocks Posted August 24, 2007 Author Share Posted August 24, 2007 Error Code: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/remotepa/public_html/Joel/index.php on line 10 Link to comment https://forums.phpfreaks.com/topic/66545-solved-problems-with-indexphp-code/#findComment-333282 Share on other sites More sharing options...
lemmin Posted August 24, 2007 Share Posted August 24, 2007 I think it is the little quotes. Try this: $sql = "SELECT * FROM users WHERE username='" . $_SESSION['username'] . "'"; Link to comment https://forums.phpfreaks.com/topic/66545-solved-problems-with-indexphp-code/#findComment-333287 Share on other sites More sharing options...
JoelRocks Posted August 24, 2007 Author Share Posted August 24, 2007 Further errors: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/remotepa/public_html/Joel/index.php on line 16 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/remotepa/public_html/Joel/index.php:16) in /home/remotepa/public_html/Joel/index.php on line 25 Link to comment https://forums.phpfreaks.com/topic/66545-solved-problems-with-indexphp-code/#findComment-333297 Share on other sites More sharing options...
GingerRobot Posted August 24, 2007 Share Posted August 24, 2007 Try: <?php session_start(); session_id($_GET['PHPSESSID']);//set php session id from URL $hostname= "localhost"; $user= "remotepa_framewo"; $password = "-"; $conn = @mysql_connect( $hostname, $user, $password ) or die ("Could not connect to server"); $db = @mysql_select_db("remotepa_framework", $conn) or die ("Could not connect to database"); $sql = "SELECT * FROM users WHERE username='".$_SESSION['username']."'"; $result = mysql_query( $sql, $conn) or die ("Could not execute query"); $output = mysql_fetch_assoc($result); if(isset($_SESSION['username'])) { if($output['active'] < 1) { echo ("Please reset your details"); echo ("Hello " .$_SESSION['username']); echo ("<br />"); echo ("You are logged in successfully"); } } else { echo ("Sorry you are not logged in"); exit; } ?> You need to start the session before any output. You also need to start it before making use of the $_SESSION array. The reason for the mysql_fetch_assoc error is because there are no results being returned by your query, because $_SESSION['username'] is undefined without starting the session previously Link to comment https://forums.phpfreaks.com/topic/66545-solved-problems-with-indexphp-code/#findComment-333306 Share on other sites More sharing options...
lemmin Posted August 24, 2007 Share Posted August 24, 2007 session_start() has to be the first function in your script. Also, change: $output = mysql_fetch_assoc($sql); to: $output = mysql_fetch_assoc($result); Link to comment https://forums.phpfreaks.com/topic/66545-solved-problems-with-indexphp-code/#findComment-333309 Share on other sites More sharing options...
JoelRocks Posted August 24, 2007 Author Share Posted August 24, 2007 Thanks both, Solved! Link to comment https://forums.phpfreaks.com/topic/66545-solved-problems-with-indexphp-code/#findComment-333312 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.