DeanWhitehouse Posted April 21, 2008 Share Posted April 21, 2008 <?php if ($_SESSION['is_valid'] == true){ if ($_SESSION['user_level'] == 2){ mysql_query("SELECT * from `$user` WHERE user_name"); echo "<table class='logged_in'><tr><td> Welcome $user_name,<br> <a href=''>User Profile</a><br> <a href=''>Settings</a> <a href='logout.php'>Logout</a> </td></tr><tr><td><font color='white'>Logged In</font></td></tr></table>"; } if ($_SESSION['user_level'] == 1){ mysql_query("SELECT * from `$user` WHERE user_name"); echo "<table class='logged_in'><tr><td> Welcome $user_name,<br> <a href=''>User Profile</a><br> <a href=''>Settings</a> <a href='logout.php'>Logout</a> </td></tr><tr><td><font color='white'>Logged In</font></td></tr></table>"; } else { include_once'login.php'; } } ?> this code is ment to display a login form if the user is not logged in, but it doesn't, and i dunno why Link to comment https://forums.phpfreaks.com/topic/102076-logged_in-display/ Share on other sites More sharing options...
DarkWater Posted April 21, 2008 Share Posted April 21, 2008 Dude. Stop using these `````` quotes on the queries. >_> Link to comment https://forums.phpfreaks.com/topic/102076-logged_in-display/#findComment-522561 Share on other sites More sharing options...
Fadion Posted April 21, 2008 Share Posted April 21, 2008 Shouldnt a normal query be: "SELECT * FROM users WHERE username='$user_name'"; ??? Link to comment https://forums.phpfreaks.com/topic/102076-logged_in-display/#findComment-522564 Share on other sites More sharing options...
DeanWhitehouse Posted April 21, 2008 Author Share Posted April 21, 2008 the table name is saved as a variable, so no to "SELECT * FROM users and i want to display the users username, but i can't think of a way to. Anyway back to the main problem, of the login page not displaying Link to comment https://forums.phpfreaks.com/topic/102076-logged_in-display/#findComment-522566 Share on other sites More sharing options...
DarkWater Posted April 21, 2008 Share Posted April 21, 2008 Yeah, Guiltygear is right. Your WHERE statement is messed up too. Link to comment https://forums.phpfreaks.com/topic/102076-logged_in-display/#findComment-522568 Share on other sites More sharing options...
DeanWhitehouse Posted April 21, 2008 Author Share Posted April 21, 2008 ok, people ignore the sql statement, Link to comment https://forums.phpfreaks.com/topic/102076-logged_in-display/#findComment-522570 Share on other sites More sharing options...
DarkWater Posted April 21, 2008 Share Posted April 21, 2008 I see the problem. The last lines look like this: else { include_once'login.php'; } } Should be: } else { include_once ('login.php'); } So that the else statement applies to the if ($_SESSION['is_valid'] == true){ conditional. =) And the include should be: include_once ('login.php'); Not: include_once'login.php'; Link to comment https://forums.phpfreaks.com/topic/102076-logged_in-display/#findComment-522572 Share on other sites More sharing options...
DeanWhitehouse Posted April 21, 2008 Author Share Posted April 21, 2008 when i remove the curly bracket i get this error Parse error: syntax error, unexpected $end in /home/www/deanwhitehouse.awardspace.co.uk/logged_in.php on line 26 and you can write includes and requires without the brackets Link to comment https://forums.phpfreaks.com/topic/102076-logged_in-display/#findComment-522575 Share on other sites More sharing options...
redarrow Posted April 21, 2008 Share Posted April 21, 2008 Do you mean this? <?php session_start(); if ($_SESSION['is_valid'] == true){ if ( ($_SESSION['user_level'] == 1) || ($_SESSION['user_level2'] == 2) ){ mysql_query("SELECT * from `$user` WHERE user_name='$user_name'"); echo "<table class='logged_in'><tr><td> Welcome $user_name,<br> <a href=''>User Profile</a><br> <a href=''>Settings</a> <a href='logout.php'>Logout</a> </td></tr><tr><td><font color='white'>Logged In</font></td></tr></table>"; }else{ include_once'login.php'; } } ?> Link to comment https://forums.phpfreaks.com/topic/102076-logged_in-display/#findComment-522577 Share on other sites More sharing options...
DarkWater Posted April 21, 2008 Share Posted April 21, 2008 when i remove the curly bracket i get this error Parse error: syntax error, unexpected $end in /home/www/deanwhitehouse.awardspace.co.uk/logged_in.php on line 26 and you can write includes and requires without the brackets You missed what I said. Move the last } to right above the else block. >_> Copy and paste exactly what I put. =/ Link to comment https://forums.phpfreaks.com/topic/102076-logged_in-display/#findComment-522580 Share on other sites More sharing options...
DeanWhitehouse Posted April 21, 2008 Author Share Posted April 21, 2008 ok, thanks, this is now my working code <?php require_once 'includes/config_table.inc.php'; require_once 'includes/db_connect.php'; mysql_query("SELECT * from `$user` WHERE user_name='$user_name'"); if ($_SESSION['is_valid'] == true){ if ($_SESSION['user_level'] == 2){ echo "<table class='logged_in'><tr><td> Welcome $user_name,<br> <a href=''>User Profile</a><br> <a href=''>Settings</a> <a href='logout.php'>Logout</a> </td></tr><tr><td><font color='white'>Logged In</font></td></tr></table>"; } if ($_SESSION['user_level'] == 1){ echo "<table class='logged_in'><tr><td> Welcome $user_name,<br> <a href=''>User Profile</a><br> <a href=''>Settings</a> <a href='logout.php'>Logout</a> </td></tr><tr><td><font color='white'>Logged In</font></td></tr></table>"; } } else { include_once ('login.php'); } ?> how can i display the user name of the user, i am using sessions and cookies Link to comment https://forums.phpfreaks.com/topic/102076-logged_in-display/#findComment-522585 Share on other sites More sharing options...
iarp Posted April 21, 2008 Share Posted April 21, 2008 <?php echo $_SESSION['user_name']; ?> Link to comment https://forums.phpfreaks.com/topic/102076-logged_in-display/#findComment-522587 Share on other sites More sharing options...
DeanWhitehouse Posted April 21, 2008 Author Share Posted April 21, 2008 ok, thanks for all the help. Link to comment https://forums.phpfreaks.com/topic/102076-logged_in-display/#findComment-522589 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.