Jump to content

[SOLVED] query not running until page refresh


lewis987

Recommended Posts

i have a login page that sets the online status to online, but it doesnt run it until the page is refreshed. any ideas?

 

this is the query that isnt working:

if($online == "y"){
		$updateSQL = "UPDATE `users` SET `online` = 'y' WHERE `username` = '$user' LIMIT 1 ;";
		echo $updateSQL;
		mysql_query($updateSQL);
	}

 

the full page is below

 

Login.php:

<?PHP
$dbhost = "localhost";
$dbuser = "xxxx";
$dbpass = "zzzz";
$dbname = "yyyy";

$error = "";
if($_POST['login']){
$username = $_POST['username'];
$password = $_POST['password'];
$online = $_POST['online'];
$pass_plain = $_POST['password'];

mysql_connect($dbhost,$dbuser,$dbpass) or die("Cannot connect to the database server");
mysql_select_db($dbname) or die("Cannot select correct database");

$username = mysql_real_escape_string($username);
$username = $username;
$username = strip_tags($username);
$username = $username;

$password = mysql_real_escape_string($password);
$password = $password;
$password = strip_tags($password);
$password = $password;
$password = md5($password);
$password = $password;

$loginCheckSQL = "SELECT * FROM `users` WHERE `username` = '$username' AND `password` = '$password';";
$loginCheckQuery = mysql_query($loginCheckSQL);
if(mysql_num_rows($loginCheckQuery) == "1"){
	if($online == "y"){
		$updateSQL = "UPDATE `users` SET `online` = 'y' WHERE `username` = '$user' LIMIT 1 ;";
		echo $updateSQL;
		mysql_query($updateSQL);
	}
	else
	{
		mysql_query("UPDATE `users` SET `online` = 'n' WHERE `username` = '$user' LIMIT 1 ;");
		echo "Offline";
	}
	$_SESSION['user'] = $username;
	$_SESSION['pass'] = $pass_plain;
	$cookie1 = setcookie("username",$_SESSION['user']);
	$cookie2 = setcookie("password",$_SESSION['pass']);
	if(!$cookie1 || !$cookie2){
		echo "Error with cookie settings.<br />";
		echo "But you have still logged in!<br />";
		echo "Click <a href='?'>here</a> to go back to the main page.";
	}
	else
	{
		echo "<br />Login sucessful!<br />
		Click <a href='?'>here</a> to go back to the main page.";
		exit;
	}
}
else
{
	$error = "Error with your login information, please look over it and correct it.";
}
mysql_close();
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login</title>
</head>

<body>
<?PHP
echo $error;
?>
<form action="" method="post">
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>Username: </td>
    <td><input name="username" type="text" /></td>
  </tr>
  <tr>
    <td>Password: </td>
    <td><input name="password" type="password" /></td>
  </tr>
  <tr>
  	<td>Do you want to appear online?</td>
    <td><select name="online">
      <option value="y">Yes</option>
      <option value="n">No</option>
    </select></td>
  <tr>
    <td colspan="2" align="right"><input name="login" type="submit" value="Login" /></td>
  </tr>
</table>

</form>
</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.