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
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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.