devilsvein Posted December 26, 2012 Share Posted December 26, 2012 Basically trying to retrieve a username to display from a table in SQL. But it doesn't display anything. Just blank. $sql = "SELECT Username FROM Persons WHERE PlayerID='".$_SESSION['ID']."'"; $result = mysqli_query($mysqli, $sql); $row = mysqli_fetch_assoc($result); $username = $row['Username']; Connection to DB is fine. Table is called Persons, Has headings Username, Password, Player ID To display it I use: <?php echo $username; ?> Quote Link to comment https://forums.phpfreaks.com/topic/272380-cant-get-username-from-table/ Share on other sites More sharing options...
Barand Posted December 26, 2012 Share Posted December 26, 2012 add this line if (!$result) die(mysqli_error($mysqli) . "<br>$sql"); Quote Link to comment https://forums.phpfreaks.com/topic/272380-cant-get-username-from-table/#findComment-1401358 Share on other sites More sharing options...
Jessica Posted December 26, 2012 Share Posted December 26, 2012 1. If player id is numeric don't surround it in quotes. 2. Don't use the session variable without escaping it. 3. Check for errors as Barand said or see the link in my signature. Quote Link to comment https://forums.phpfreaks.com/topic/272380-cant-get-username-from-table/#findComment-1401360 Share on other sites More sharing options...
Langstra Posted December 26, 2012 Share Posted December 26, 2012 Check if you have called session_start() and then check if $_SESSION['ID'] contains a value. Just echo it. Quote Link to comment https://forums.phpfreaks.com/topic/272380-cant-get-username-from-table/#findComment-1401361 Share on other sites More sharing options...
devilsvein Posted December 26, 2012 Author Share Posted December 26, 2012 Thanks guys, found it to be that the session variables weren't carrying the data from the login page but still managing to log in. (weird!). Found the issue to be a code i found online to reduce session hijacking. Oh well. Back to using session_start(); only lol Quote Link to comment https://forums.phpfreaks.com/topic/272380-cant-get-username-from-table/#findComment-1401397 Share on other sites More sharing options...
Christian F. Posted December 26, 2012 Share Posted December 26, 2012 After confirming the user's login information, you should use session_regenerate_id (), and that's all you need to prevent session fixation (which is one form of hijacking attack). Quote Link to comment https://forums.phpfreaks.com/topic/272380-cant-get-username-from-table/#findComment-1401400 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.