imdead Posted June 17, 2008 Share Posted June 17, 2008 Hey Guys, Whats Wrong With This, I Cant Spot The Error. It's Not Echo'ing Anything Out > <?php if(session_is_registered('username')){ $sql = mysql_query("SELECT * FROM users"); if (mysql_num_rows($sql) == 1){ $row = mysql_fetch_assoc($sql); $userlevel = $row['userlevel']; if ($userlevel === '1'){ echo"<a href='admin.php'>Admin Panel</a> // "; } }} ?><a href="http://jigsaw.w3.org/css-validator/check/referer">Valid CSS</a> Quote Link to comment https://forums.phpfreaks.com/topic/110639-solved-echomysql/ Share on other sites More sharing options...
trq Posted June 17, 2008 Share Posted June 17, 2008 if ($userlevel == 1) { Quote Link to comment https://forums.phpfreaks.com/topic/110639-solved-echomysql/#findComment-567627 Share on other sites More sharing options...
imdead Posted June 18, 2008 Author Share Posted June 18, 2008 Nope Still echo'ing nothing Quote Link to comment https://forums.phpfreaks.com/topic/110639-solved-echomysql/#findComment-567997 Share on other sites More sharing options...
serverman Posted June 18, 2008 Share Posted June 18, 2008 try removing the // Quote Link to comment https://forums.phpfreaks.com/topic/110639-solved-echomysql/#findComment-568001 Share on other sites More sharing options...
mmarif4u Posted June 18, 2008 Share Posted June 18, 2008 I am not sure whether it will solve Or not: change your session like: And add mysql error reporting. <?php if($_SESSION('username')){ $sql = mysql_query("SELECT * FROM users") or die (mysql_error()); if (mysql_num_rows($sql) == 1){ $row = mysql_fetch_assoc($sql); $userlevel = $row['userlevel']; if ($userlevel == '1'){ echo"<a href='admin.php'>Admin Panel</a> // "; } }} ?> Quote Link to comment https://forums.phpfreaks.com/topic/110639-solved-echomysql/#findComment-568002 Share on other sites More sharing options...
imdead Posted June 18, 2008 Author Share Posted June 18, 2008 Fatal error: Function name must be a string in C:\xampp\htdocs\footer.php on line 3 Also If I Add This <?php if(session_is_registered('username')){ $sql = mysql_query("SELECT * FROM users"); if (mysql_num_rows($sql) == 1){ $row = mysql_fetch_assoc($sql); $userlevel = $row['userlevel']; if ($userlevel == '1'){ echo"<a href='admin.php'>Admin Panel</a> // "; } } }else{ echo 'blah blah not logged in'; } ?> When Your Not logged in, you get blah blah not logged in Quote Link to comment https://forums.phpfreaks.com/topic/110639-solved-echomysql/#findComment-568006 Share on other sites More sharing options...
mmarif4u Posted June 18, 2008 Share Posted June 18, 2008 Did you try this: <?php if($_SESSION['username']){ $sql = mysql_query("SELECT * FROM users") or die (mysql_error()); if (mysql_num_rows($sql) == 1){ $row = mysql_fetch_assoc($sql); $userlevel = $row['userlevel']; if ($userlevel == '1'){ echo"<a href='admin.php'>Admin Panel</a> // "; } else { echo "Error: not loged in"; } }} ?> Quote Link to comment https://forums.phpfreaks.com/topic/110639-solved-echomysql/#findComment-568008 Share on other sites More sharing options...
imdead Posted June 18, 2008 Author Share Posted June 18, 2008 Yep I Don't Get Anything, Logged in or out with that Quote Link to comment https://forums.phpfreaks.com/topic/110639-solved-echomysql/#findComment-568011 Share on other sites More sharing options...
mmarif4u Posted June 18, 2008 Share Posted June 18, 2008 It mean that session is not registered. try this: and post output. <?php if($_SESSION['username']){ $sql = mysql_query("SELECT * FROM users") or die (mysql_error()); if (mysql_num_rows($sql) == 1){ $row = mysql_fetch_assoc($sql); $userlevel = $row['userlevel']; if ($userlevel == '1'){ echo"<a href='admin.php'>Admin Panel</a> // "; } else { echo "Error: not loged in"; } }} else { echo "session not registered"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/110639-solved-echomysql/#findComment-568013 Share on other sites More sharing options...
imdead Posted June 18, 2008 Author Share Posted June 18, 2008 When I'm Not Logged In I Get session not registered When I Am Logged In As Both, User And Admin I Still Get Nothing On Eaither Quote Link to comment https://forums.phpfreaks.com/topic/110639-solved-echomysql/#findComment-568020 Share on other sites More sharing options...
mmarif4u Posted June 18, 2008 Share Posted June 18, 2008 Can you post your complete code for this page. Quote Link to comment https://forums.phpfreaks.com/topic/110639-solved-echomysql/#findComment-568022 Share on other sites More sharing options...
imdead Posted June 18, 2008 Author Share Posted June 18, 2008 That Is The Entire Code, It's The Footer.php Quote Link to comment https://forums.phpfreaks.com/topic/110639-solved-echomysql/#findComment-568026 Share on other sites More sharing options...
trq Posted June 18, 2008 Share Posted June 18, 2008 You need to call session_start() prior to using the $_SESSION array. <?php session_start(); if (isset($_SESSION['username'])) { if ($result = mysql_query("SELECT userlevel FROM users WHERE username = '{$_SESSION['username']}'")) { if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($sql); $userlevel = $row['userlevel']; if ($userlevel == 1) { echo"<a href='admin.php'>Admin Panel</a> // "; } } else { echo "Error: not loged in"; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/110639-solved-echomysql/#findComment-568032 Share on other sites More sharing options...
mhodge_txs Posted June 18, 2008 Share Posted June 18, 2008 <?php if($_SESSION['username']){ $sql = mysql_query("SELECT * FROM users") or die (mysql_error()); if (mysql_num_rows($sql) == 1){ $row = mysql_fetch_assoc($sql); $userlevel = $row['userlevel']; if ($userlevel == '1'){ echo"<a href='admin.php'>Admin Panel</a> // "; }else{ echo "Error: not loged in"; } } }else { echo "session not registered"; } ?> Suggestions: 1.) you need a where statement in your sql query in order to get one user; 2.) do a var_dump of $userlevel to see if its a string or an integer this will help you in choosing =="1" or ==1 in your if statement 3.) Are you sure you have called session_start(); on the pages that make use of this footer Quote Link to comment https://forums.phpfreaks.com/topic/110639-solved-echomysql/#findComment-568033 Share on other sites More sharing options...
imdead Posted June 18, 2008 Author Share Posted June 18, 2008 yes session start is called in the header.php if i use a where <?php if($_SESSION['username']){ $sql = mysql_query("SELECT * FROM users WHERE username={$_SESSION['username']}") or die (mysql_error()); if (mysql_num_rows($sql) == 1){ $row = mysql_fetch_assoc($sql); $userlevel = $row['userlevel']; if ($userlevel == '1'){ echo"<a href='admin.php'>Admin Panel</a> // "; } else { echo "Error: not loged in"; } }} else { echo "session not registered"; } ?> I Get Unknown column 'kevski' in 'where clause' Quote Link to comment https://forums.phpfreaks.com/topic/110639-solved-echomysql/#findComment-568035 Share on other sites More sharing options...
trq Posted June 18, 2008 Share Posted June 18, 2008 Look at the query I posted in my code, then look at yours. Quote Link to comment https://forums.phpfreaks.com/topic/110639-solved-echomysql/#findComment-568040 Share on other sites More sharing options...
mhodge_txs Posted June 18, 2008 Share Posted June 18, 2008 I use sprintf when formulating a sql query thats my preference http://www.php.net/sprintf have a read <?php if($_SESSION['username']){ $query = sprintf("SELECT * FROM users WHERE username='%s'", $_SESSION['username']); $sql = mysql_query($query) or die (mysql_error()); if (mysql_num_rows($sql) == 1){ $row = mysql_fetch_assoc($sql); $userlevel = $row['userlevel']; if ($userlevel == '1'){ echo"<a href='admin.php'>Admin Panel</a> // "; }else{ echo "Error: not loged in"; } } } else { echo "session not registered"; } ?> Im not sure about the line " if ($userlevel == '1'){ " because I dont know if the $userlevel variable is storing a int or string, do a var_dump($userlevel) to find this out. Quote Link to comment https://forums.phpfreaks.com/topic/110639-solved-echomysql/#findComment-568043 Share on other sites More sharing options...
imdead Posted June 18, 2008 Author Share Posted June 18, 2008 Thanks Guys It's All Fixed Also vardump gave me // string(1) "1" Quote Link to comment https://forums.phpfreaks.com/topic/110639-solved-echomysql/#findComment-568052 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.