Hi

I really need some help with PHP

I am trying code something like the following

After a user logs in, I want a page to display his username, how do I do that

On the page where I want to display the username, I have got the following PHP coding so far

PHP Code:
<?php
//set vars
$user $_POST['user'];
$pass md5($_POST['pass']);

if (
$user&&$pass
{
//connect to db
$connect mysql_connect("$hostname","$username","$password") or die("not connecting");
mysql_select_db("databasename") or die("no db :'(");
$query mysql_query("SELECT * FROM $tablename WHERE username='$user'");
?>
My login php page coding is below

PHP Code:
<?php
//set vars
$user $_POST['user'];
$pass md5($_POST['pass']);

if (
$user&&$pass
{
//connect to db
$connect mysql_connect("$hostname","$username","$password") or die("not connecting");
mysql_select_db("databasename") or die("no db :'(");
$query mysql_query("SELECT * FROM $tablename WHERE username='$user'");

$numrows mysql_num_rows($query);


if (
$numrows!=0)
{
//while loop
  
while ($row mysql_fetch_assoc($query))
  {
    
$dbusername $row['username'];
    
$dbpassword $row['password'];
  }
  else
      die(
"incorrect username/password!");
}
else
  echo 
"user does not exist!";

else
    die(
"please enter a username and password!");
?>
<br>
<div id="login">
Enter username and password below to login
</div>
<form id='login' action='checklogin.php' method='post' accept-charset='UTF-8'>
<fieldset>
<legend></legend>
<input type='hidden' name='submitted' id='submitted' value='1'/>
<label for='username' >Username*:</label>
<input type='text' name='username' id='username'  maxlength="50" />
<label for='password' >Password*:</label>
<input type='password' name='password' id='password' maxlength="50" />
<input type='submit' name='Submit' value='Login' />
</fieldset>
</form>
<br><br>
<div id="forgot">
Enter your registered email address below to generate a new password
</div>
<form method="post" action="forgotpassword.php">
<label for="email">Email:</label>
<input type="text" title="Please enter your email address" name="email" size="30"/>
<input type="submit" value="Submit" class="submit-button"/>
</form>
My registration form coding is below

PHP Code:
<?php
//=============Configuring Server and Database=======
$host        =    'hostname';
$user        =    'username';
$password    =    'password';
//=============Data Base Information=================
$database    =    'databasename';
 
$conn        =    mysql_connect($host,$user,$password) or die('Server Information is not Correct'); //Establish Connection with Server
mysql_select_db($database,$conn) or die('Database Information is not correct');
 
//===============End Server Configuration============
 
//=============Starting Registration Script==========
 
$email    =    $_POST['email'];

$username    =    $_POST['txtUser'];
 
$password    =    $_POST['txtPassword'];
 
//=============To Encrypt Password===================
$password    =    md5($salt.$password);
//============New Variable of Password is Now with an Encrypted Value========
 
if(isset($_POST['btnRegister'])) //===When I will Set the Button to 1 or Press Button to register
{
$query    =    "insert into users(email,username,password)values('$email','$username','$password')";
$res    =    mysql_query($query);
header('location:registersuccess.html');
}
 
?>

<?php
$to 
"$email";
$subject "Registration Details";
$message "Email: $email \n Username: $username \n Password: $password";
$from "myemailaddress";
$headers "From: $from";
mail($to,$subject,$message,$headers);
echo 
"Mail Sent.";
?>
Thank you in advance

Kind regards

Ian