View Single Post
  #1 (permalink)  
Old Apr 27th, 2008, 15:31
peter12345 peter12345 is offline
New Member
Join Date: Apr 2008
Location: UK
Age: 30
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] Php Sessions

Hi,

I have created a website with a registration form & login form and a uniqueId mysql database to validate the user trying to login. Once user is successfully logged in they are directed to a page were i would like there details to auto display from the database.

I no i have to use sessions but am having trouble understanding could someone help me.

Here is my working login form:

PHP: Select all

<?php
ob_start
();
$host="localhost"// Host name 
$username="web36-dbelite"// Mysql username 
$password="longstand"// Mysql password 
$db_name="web36-dbelite"// Database name 
$tbl_name="tbl_worker"// Table name 

// Connect to server and select databse.
mysql_connect("$host""$username""$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// Define $myusername and $mypassword 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword']; 

// To protect MySQL injection (more detail about MySQL injection)
$myusername stripslashes($myusername);
$mypassword stripslashes($mypassword);
$myusername mysql_real_escape_string($myusername);
$mypassword mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE workerusername='$myusername' and workerpassword='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");

 
header("location:   Your_account.php  " );
}
else {
echo 
"Wrong Username or Password";
}

ob_end_flush();
?>
Reply With Quote