Jump to content

[SOLVED] user page load name


perezf

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/67590-solved-user-page-load-name/
Share on other sites

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>

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();

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.