avizhome
03-25-2010, 03:25 PM
Hi,
I have a table in my index.php page in which i have the login form, once the users enters their login credential, it takes them to login.php page & here i do my database query. Now if it is a succesfully query i.e the login credentials are correct it should take the user back to the index.php page but the table that previous had the login form should not be there but instead a welcome message.
This is my index.php code:
<?
if (!isset($_SESSION['username'])){
echo "<form id='form1' name='form1' method='post' action='login.php'>";
echo "<table width='100%' border='1'>";
echo "<tr>";
echo "<td bgcolor='#000000'><div align='center' class='WDWD'><strong>MEMBER LOGIN</strong></div></td>";
echo "</tr>";
echo "<tr>";
echo "<td>USER";
echo "<label>";
echo "<input type='text' name='user' id='user' />";
echo "</label></td>";
echo "</tr>";
echo "<tr>";
echo "<td>PASS";
echo "<label>";
echo "<input type='text' name='pass' id='pass' />";
echo "</label></td>";
echo "</tr>";
echo "<tr>";
echo "<td><label>";
echo "<input type='submit' name='button' id='button' value='Submit' />";
echo "</label></td>";
echo "</tr>";
echo "<tr>";
echo "<td>IF NOT A MEMBER, CLICK HERE TO REGISTER</td>";
echo "</tr>";
echo "</table>";
echo "</form></td>";
}
else{
echo "Welcome message";
}
?>
And this is my login.php page:
<?
$host="localhost"; // Host name
$username="*****"; // Mysql username
$password="*****"; // Mysql password
$db_name="*****"; // Database name
$tbl_name="*****"; // Table name
$user=$_POST['user'];
$pass=$_POST['pass'];
// Connect to server and select databse.
$con= mysql_connect("$host", "$username", "$password");
if (!$con){
die("cannot connect");
}
mysql_select_db($db_name, $con);
$sql="SELECT * FROM $tbl_name WHERE user_name='$user' and pass='$pass'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if ($count==1){
session_start();
$_SESSION['username'] = $user;
header("location:index_beta.php?");
//If login is successfull then users should be directed to the login page but the table which previously has the login form should now contain the welcome message
}
else{
//if login is not successfull, it should again take users back to the index.php page but the table with login form should be there :)
}
?>
Thank you for your support :)
I have a table in my index.php page in which i have the login form, once the users enters their login credential, it takes them to login.php page & here i do my database query. Now if it is a succesfully query i.e the login credentials are correct it should take the user back to the index.php page but the table that previous had the login form should not be there but instead a welcome message.
This is my index.php code:
<?
if (!isset($_SESSION['username'])){
echo "<form id='form1' name='form1' method='post' action='login.php'>";
echo "<table width='100%' border='1'>";
echo "<tr>";
echo "<td bgcolor='#000000'><div align='center' class='WDWD'><strong>MEMBER LOGIN</strong></div></td>";
echo "</tr>";
echo "<tr>";
echo "<td>USER";
echo "<label>";
echo "<input type='text' name='user' id='user' />";
echo "</label></td>";
echo "</tr>";
echo "<tr>";
echo "<td>PASS";
echo "<label>";
echo "<input type='text' name='pass' id='pass' />";
echo "</label></td>";
echo "</tr>";
echo "<tr>";
echo "<td><label>";
echo "<input type='submit' name='button' id='button' value='Submit' />";
echo "</label></td>";
echo "</tr>";
echo "<tr>";
echo "<td>IF NOT A MEMBER, CLICK HERE TO REGISTER</td>";
echo "</tr>";
echo "</table>";
echo "</form></td>";
}
else{
echo "Welcome message";
}
?>
And this is my login.php page:
<?
$host="localhost"; // Host name
$username="*****"; // Mysql username
$password="*****"; // Mysql password
$db_name="*****"; // Database name
$tbl_name="*****"; // Table name
$user=$_POST['user'];
$pass=$_POST['pass'];
// Connect to server and select databse.
$con= mysql_connect("$host", "$username", "$password");
if (!$con){
die("cannot connect");
}
mysql_select_db($db_name, $con);
$sql="SELECT * FROM $tbl_name WHERE user_name='$user' and pass='$pass'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if ($count==1){
session_start();
$_SESSION['username'] = $user;
header("location:index_beta.php?");
//If login is successfull then users should be directed to the login page but the table which previously has the login form should now contain the welcome message
}
else{
//if login is not successfull, it should again take users back to the index.php page but the table with login form should be there :)
}
?>
Thank you for your support :)