Hi guys,
I have been staring at this for too long and need a fresh set of eyes, if possible?
I want to run the code below above my html page so that if the login is successful I get redirect using 'headerlocation'.
However if the errors array isnt empty i want to echo the errors inside the body of my html page.
I have run into probs when rying to move the block of code cause there is a conflict with the closing bracket of 'check if form was submitted'
PHP Code:<?
// strt session
session_start();
// error reporting
error_reporting(E_ALL);
ini_set('display_errors', true);
// include config file
include "CMS/config.php";
// Check if the form has been submitted.
if (isset($_POST['submitted'])) {
// Connect to the database
include("CMS/script-files/db-connect.php");
// Initialise the errors array
$errors = array();
// validate the login submission
if (empty($_POST['email'])) {
$errors[] ="Please enter your email address.";
}
if (empty($_POST['pass'])) {
$errors[] ="Please enter your password.";
}
$e = $_POST['email'];
$p = $_POST['pass'];
// If the variables exist, lets continue
if ($e && $p) {
// Check if the user id and password combination exist in database
$sql = "SELECT email, first_name, member_id FROM members WHERE email='$e' AND member_pass=SHA('$p') AND active='Y'";
$result = mysql_query($sql)
or die('Query failed. ' . mysql_error());
// if it find a match, continue
if (mysql_num_rows($result) == 1) {
while($row=mysql_fetch_array($result))
{
// the user id and password match, lets continue
// lets set the session
$_SESSION['first_name'] = $row['first_name'];
$_SESSION['members_id'] = $row['member_id'];
$_SESSION['username'] = $row['email'];
}
// if no match was find, report error
} else {
$errors[] ="Sorry, wrong email / password.";
}
}
// If everything went okay and there were no errors, continue.
if (empty($errors)) {
// after login we move to the main page
header('Location: http://www.domainname/members-area/');
exit;
// if errors array contains a value
} else {
echo "<table align=\"center\"><tr><td><b>The following error(s) occurred:</b><br /><blockquote>";
foreach ($errors as $msg) { // Print each error.
echo "* $msg<br />\n";
}
echo '</blockquote></td></tr></table>';
}
}
?>
..html page goes here
hoping to place the echo - error code here '// if errors array contains a value'






Bookmarks