Liam Macmillan
New member
Hello, I am making Log in for my site.. I want to make it so when you log in it displays your username by saying 'Welcome, Liam' but when I try this it just says 'Welcome, $user'.. Can anyone help?!
Here is the code for the page that says 'Welcome, $user':
<?php
session_start();
echo "Welcome, ".$_SESSION['user']."!"
?>
Here is the code for the Log In page:
<?php
if (isset($_REQUEST['attempt']))
{
$link = mysql_connect('NOT TELLING', 'NOT TELLING', 'NOT TELLING') or die('Cant connect to database');
mysql_select_db(NOT TELLINGt');
$user = mysql_real_escape_string($_POST['user']);
$password = sha1(mysql_real_escape_string($_POST['password']));
$query = mysql_query("
SELECT user
FROM users
WHERE user = '$user'
AND password = '$password'
") or die(mysql_error());
$total = mysql_num_rows($query);
if ($total > 0)
{
session_start();
$_SESSION['user'] = $user;
header('location: junk.php');
}
if ($user==$dbuser&&$password==$dbpassword)
{
echo "You're in!";
$_SESSION['user'] = $user;
}
else
{
die('Incorrect username or password!<br /> <span class="Cagain"><a href="http://www.youropenlife.com/index.php">Click here to try again</a></span>');
}
}
?>
Can anybody help with this? If this helps my website is www.youropenlife.com
Username: Abdullah
Password: Abz
Many thanks, Liam!
Here is the code for the page that says 'Welcome, $user':
<?php
session_start();
echo "Welcome, ".$_SESSION['user']."!"
?>
Here is the code for the Log In page:
<?php
if (isset($_REQUEST['attempt']))
{
$link = mysql_connect('NOT TELLING', 'NOT TELLING', 'NOT TELLING') or die('Cant connect to database');
mysql_select_db(NOT TELLINGt');
$user = mysql_real_escape_string($_POST['user']);
$password = sha1(mysql_real_escape_string($_POST['password']));
$query = mysql_query("
SELECT user
FROM users
WHERE user = '$user'
AND password = '$password'
") or die(mysql_error());
$total = mysql_num_rows($query);
if ($total > 0)
{
session_start();
$_SESSION['user'] = $user;
header('location: junk.php');
}
if ($user==$dbuser&&$password==$dbpassword)
{
echo "You're in!";
$_SESSION['user'] = $user;
}
else
{
die('Incorrect username or password!<br /> <span class="Cagain"><a href="http://www.youropenlife.com/index.php">Click here to try again</a></span>');
}
}
?>
Can anybody help with this? If this helps my website is www.youropenlife.com
Username: Abdullah
Password: Abz
Many thanks, Liam!