perezf Posted September 2, 2007 Share Posted September 2, 2007 im trying to load the user name from my database so after the user is logged in they will see Welcome user! right now it just shows welcome am i calling the name from the database wrong <?php session_start(); if(!session_is_registered('username')) { header("Location: http://localhost/practice.com/?page=log-on"); } $sessionid = session_is_registered('username'); $query = "SELECT username FROM ph_users WHERE username = '$sessionid'"; $result = mysql_query($query); $row = mysql_fetch_row($result); ?> ONLY MEMBERS CAN VIEW THIS PAGE <p>Welcome <?php echo $row['username']; ?></p> <p><a href="?page=logout">LogOut</a></p> Quote Link to comment https://forums.phpfreaks.com/topic/67590-solved-user-page-load-name/ Share on other sites More sharing options...
Fadion Posted September 2, 2007 Share Posted September 2, 2007 Not very sure, but mysql_fetch_row() returns data with numeric indexes. Try echoing $row[0] or just use mysql_fetch_array(). Quote Link to comment https://forums.phpfreaks.com/topic/67590-solved-user-page-load-name/#findComment-339533 Share on other sites More sharing options...
perezf Posted September 2, 2007 Author Share Posted September 2, 2007 i tried this and the username still does not load after the welcome, am i missing something <?php session_start(); if(!session_is_registered('username')) { header("Location: http://localhost/practice.com/?page=log-on"); } $sessionid = session_is_registered('username'); $query = "SELECT username FROM ph_users WHERE username = '$sessionid'"; $result = mysql_query($query); $row = mysql_fetch_array($result); ?> ONLY MEMBERS CAN VIEW THIS PAGE <p>Welcome <?php echo $row['username']; ?></p> <p><a href="?page=logout">LogOut</a></p> Quote Link to comment https://forums.phpfreaks.com/topic/67590-solved-user-page-load-name/#findComment-339534 Share on other sites More sharing options...
Fadion Posted September 2, 2007 Share Posted September 2, 2007 session_is_registered() will return true/false depending if the session is set. Instead of that u can just use isset($_SESSION['username']);. I find it better that way but thats not your problem. Actually u are assigning TRUE to $sessionid with session_is_registered(). Instead use: $sessionid = session_id(); session_start(); Quote Link to comment https://forums.phpfreaks.com/topic/67590-solved-user-page-load-name/#findComment-339540 Share on other sites More sharing options...
Fadion Posted September 2, 2007 Share Posted September 2, 2007 Just figured it out that u dont actually need the session id. U just need the session value: $sessionid = $_SESSION['username']; //the other code Quote Link to comment https://forums.phpfreaks.com/topic/67590-solved-user-page-load-name/#findComment-339541 Share on other sites More sharing options...
perezf Posted September 2, 2007 Author Share Posted September 2, 2007 for some reason i can figure this out :( what do i do <?php session_start(); if(!session_is_registered('username')) { header("Location: http://localhost/practice.com/?page=log-on"); } $sessionid = $_SESSION['username']; $query = "SELECT username FROM ph_users WHERE username = '$sessionid'"; $result = mysql_query($query); $row = mysql_fetch_array($result); ?> ONLY MEMBERS CAN VIEW THIS PAGE <p>Welcome <?php echo $row['username']; ?></p> <p><a href="?page=logout">LogOut</a></p> Quote Link to comment https://forums.phpfreaks.com/topic/67590-solved-user-page-load-name/#findComment-339543 Share on other sites More sharing options...
Fadion Posted September 2, 2007 Share Posted September 2, 2007 Its right in that way. It isnt working? If not echo $sessionid to see if it gets a value. Quote Link to comment https://forums.phpfreaks.com/topic/67590-solved-user-page-load-name/#findComment-339545 Share on other sites More sharing options...
perezf Posted September 2, 2007 Author Share Posted September 2, 2007 yes it returned a value of 1 Quote Link to comment https://forums.phpfreaks.com/topic/67590-solved-user-page-load-name/#findComment-339548 Share on other sites More sharing options...
Fadion Posted September 2, 2007 Share Posted September 2, 2007 Value of 1? Ok, what value did u assign to the session 'username'? Isnt it the username of the user who just logged in? In the database, the field 'username' contains the username of the users (ex. John)? Quote Link to comment https://forums.phpfreaks.com/topic/67590-solved-user-page-load-name/#findComment-339549 Share on other sites More sharing options...
perezf Posted September 2, 2007 Author Share Posted September 2, 2007 thank you i got it now Quote Link to comment https://forums.phpfreaks.com/topic/67590-solved-user-page-load-name/#findComment-339550 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.