QUOTE
<?php
session_start();
require 'connect.php';
$act = $_REQUEST[act];
$ip = $_SERVER['REMOTE_ADDR'];
$timestamp = date("m-d-Y g:i:s A");
if ($act = login){
if (isset($_POST['txtUserId']) && isset($_POST['txtPassword'])) {
$userId = $_POST['username'];
$password = $_POST['password'];
// check if the user id and password combination exist in database
$sql = "SELECT *
FROM member
WHERE username = '$userId' AND password = '$password'";
$result = mysql_query($sql) or die('Query failed. ' . mysql_error());
while($row = mysql_fetch_array($result)) {
$locaton = .$row[access_location];
}
if (mysql_num_rows($result) == 1) {
// the user id and password match,
// set the session
$_SESSION['logged_in'] = true;
$sql = "INSERT INTO member ('last_log_on', 'ip') VALUES ( '$timestamp', '$ip') WHERE username = $userID'";
$result2 = mysql_query($sql) or die ("Not working try again");
$sql2 = "UPDATE members SET online = (1) WHERE username ='$userID'";
$result3 = mysql_query($sql2) or die ("Not working try again");
header ('location: $location');
} else {
$errorMessage = '<warning>Sorry, wrong username / password</warning>';
}
};
print $errorMessage;
?>
I'll work on this code.
You should at start connect to your mysql server:
CODE
/* Change at will */
$host = 'localhost';
$db = 'mydb';
$dbuser = 'SicarulZ'
$dbpassword = '0123456789';
$conn = mysql_connect($host, $dbuser, $dbpassword);
mysql_select_db($db);
The code in red is dangerous for your SQL Database, be careful.
You should check that it's a safe string... you can easily do:
CODE
$userId = mysql_real_escape_string($userId, $conn);
$password = mysql_real_escape_string($password, $conn);
The "loggedin" variable you set isn't useful at all, as just having user and password set is enough, i would also recommend to encrypt passwords in database with MD5...
Well, try it fixing those things, or fix them on your own code, i hope you get it working soon