pingeyeg
asked on
Have message come after user tries to login
I would like to have my code where nothing happens until the user tries to login. RIght now, the code runs as the page loads, therefore outputting the error message. I don't want the error message to be displayed until a user tries to login.
<?php
session_start();
//Pulling info from login page
if ($_SERVER['REQUEST_METHOD' ] == "POST") {
$strUsername = $_POST['strUsername'];
$strPassword = $_POST['strPassword'];
}
//Connect to the database
$conn = mysql_connect("localhost", "username", "password")
or die(mysql_error());
mysql_select_db("bank");
//Select info from the database
$sql_select = mysql_query("select * from login where strUsername = '" . $strUsername . "' and strPassword = '" . md5($strPassword) . "'")
or die(mysql_error());
if(mysql_num_rows($sql_sel ect) != 0)
{
$_SESSION["username"] = $strUsername;
header("location: index.php");
}
else
{
$result = "You are not authorized, please register with us.";
}
session_write_close();
?>
<?php
session_start();
//Pulling info from login page
if ($_SERVER['REQUEST_METHOD'
$strUsername = $_POST['strUsername'];
$strPassword = $_POST['strPassword'];
}
//Connect to the database
$conn = mysql_connect("localhost",
or die(mysql_error());
mysql_select_db("bank");
//Select info from the database
$sql_select = mysql_query("select * from login where strUsername = '" . $strUsername . "' and strPassword = '" . md5($strPassword) . "'")
or die(mysql_error());
if(mysql_num_rows($sql_sel
{
$_SESSION["username"] = $strUsername;
header("location: index.php");
}
else
{
$result = "You are not authorized, please register with us.";
}
session_write_close();
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER