Hi Guys, I created a basic login page, but for some reason when I try to initially login the login page is just reloaded instead of accessing the system.
After that first attempt, if I try to login again I'm successfully brought to the test system.
So it sounds like a session problem to me, but I can't see where the problem is 8-/
Here's ye olde code
<?php
require_once ('database.php');
require_once('functions.php');
if($_SERVER['REQUEST_METHOD'] == "POST"){
$errors = array();
if(empty($_POST['password'])){
$errors = array_merge($errors, "Please enter a password");
}
if(empty($_POST['username'])){
$errors = array_merge($errors, "Please enter a username");
}
if(!count($errors)){
$md5Password = md5(trim($_POST['password']));
$query = "SELECT username from users WHERE password = '$md5Password' AND username ='" . $_POST['username'] . "'";
$result = mysql_query("$query") or die("<BR>Query failed <BR>" . "MySQL Error Number : " . mysql_errno() . " Error : " . mysql_error() . "<BR>" . "<a href=\"javascript:history.back()\">Previous Page</a>");
$countOfRows = mysql_num_rows($result);
if ($countOfRows == 1){
$query = "select testValue from testTable where userID = \"" . trim($_POST['username']) . "\"";
$result = mysql_query($query) or die("<BR>Query failed <BR>" . "MySQL Error Number : " . mysql_errno() . " Error : " . mysql_error() . "<BR>Query = " . $query . "<BR>" . "<a href=\"javascript:history.back()\">Previous Page</a>");
$regions = array();
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
$regions = array_merge($regions, $row[0]);
}
// initiate a session
session_start();
// registering session variables
session_register("SESSION");
session_register("REGION");
$_SESSION['count'] = 0;
// including the username
$_SESSION['SESSION'] = $_POST['username'];
$_SESSION['REGION'] = $regions;
mysql_free_result ( $result );
// redirect to protected page
header("Location: " . $path . "test.php?closed=0");
}
}
}
?>
Has anyone come across something like this? Any comments or suggestions would be appreciated - and sorry about the formatting, when I copy it in it seems to lose its spacing 8-/