I have a script to manage user login and when the username is in-putted into the field and the password is in-putted into it's field and they match to the db you log in if not you get an error returned parsed by the login form. however when you input an invalid value into the username (a username that doesn't exist) the code doesn't continue so how do I fix that??
<?php
require("bootstrap.php");
$con=mysql_connect(DB_HOST,DB_USER_SEC,DB_PASS_SEC) or die("Failed to connect to MySQL: " . mysql_error());
$db=mysql_select_db(DB_NAME_SEC,$con) or die("Failed to connect to MySQL: " . mysql_error());
$query = mysql_query("SELECT * FROM username WHERE userName = '$_POST[username]'") or die(mysql_error());
if(!empty($_POST['username']))
{
if(!empty($_POST['password']))
{
$row = mysql_fetch_array($query) or die(mysql_error());
if(!empty($row['userName']))
{
if(!empty($row['userPass']))
{
if($_POST['password'] === $row['userPass'])
{
session_start();
$_SESSION['logged'] = true;
$_SESSION['userName'] = $row['userName'];
$_SESSION['fname'] = $row['fname'];
$_SESSION['mname'] = $row['mname'];
$_SESSION['lname'] = $row['lname'];
$_SESSION['primnum'] = $row['primnum'];
$_SESSION['secnum'] = $row['secnum'];
$_SESSION['department'] = $row['department'];
$_SESSION['clearance'] = $row['clearance'];
$_SESSION['theme'] = $row['theme'];
$_SESSION['animations'] = $row['animations'];
$_SESSION['gtag'] = $row['gtag'];
header("Location: /workspace/index");
}
else
{
session_start();
$_SESSION['logged'] = false;
$_SESSION['err'] = "0x001";
header("Location: /login");
}
}
else
{
session_start();
$_SESSION['logged'] = false;
$_SESSION['err'] = "0x005";
header("Location: /login");
}
}
else
{
session_start();
$_SESSION['logged'] = false;
$_SESSION['err'] = "0x002";
header("Location: /login");
}
}
else
{
session_start();
$_SESSION['logged'] = false;
$_SESSION['err'] = "0x003";
header("Location: /login");
}
}
else
{
session_start();
$_SESSION['logged'] = false;
$_SESSION['err'] = "0x004";
header("Location: /login");
}
?>
and yes I know about MySqli and PDO so PLEASE DO NOT Bring that Up.
error_reporting(E_ALL); ini_set('display_errors',1);session_start();in everyelsecondition. Why not you writesession_start();at the top of your page once.mysqliandPDOwhy aren't you using them? ThemysqlAPI will be removed in the next release of PHP. What then?