Jump to content

[SOLVED] My update query wont work however I don't get a error


Twister1004

Recommended Posts

Hey everyone! I've been having a little trouble with this script, however I don't see why. I've ran tests but I've not received an error. It also doesn't want to work.

 

Objective: Figure out why this Query wont work.

 

Problem:

$loginchange = mysql_query("UPDATE `1amyth_account` SET `loggedin` = '1' WHERE `username` = '$username'");

 

You can see I'm trying to UPDATE the table "loggedin" to 1 from 0 showing the account is logged in and can be tracked.

Then I'm going to, later, turn it back to 0 when they log out.

 

Whole Code

<?php error_reporting(E_ALL);
include("inc/config2.php");
	if (isset($_POST['username'])) {
		$username = mysql_real_escape_string(trim($_POST['username']));
		$password = mysql_real_escape_string(trim($_POST['password']));
/*-------------------------------Attempt to Login--------------------------------------------*/
		$sql = mysql_query("SELECT * FROM `lamyth_account` WHERE `username` = '$username' AND `password` = '$password' LIMIT 1") or die("Contact the Admin with this id / code " . mysql_error());
		if (mysql_num_rows($sql) == 0) die("Invalid Username or Password. <br/>Please go back and re-enter your information.");
		while ($data = mysql_fetch_assoc($sql)) {
			if (!isset($_SESSION['login_id'])) {
				$_SESSION['login_id'] = $data['accountid'];
				$_SESSION['login_user'] = $data['username'];
				$_SESSION['login_pass'] = $data['password'];
				$lastlogin = mysql_query("UPDATE `lamyth_account` SET `last_login`= NOW() WHERE `username` = '$username'");
				$loginchange = mysql_query("UPDATE `1amyth_account` SET `loggedin` = '1' WHERE `username` = '$username'");
			}
			else break;
		}
	}
	@$user = $_SESSION['login_id'];
if (isset($_SESSION['login_user'])){ ?>
<div style="">
	<?php echo "Welcome, {$_SESSION['login_user']}.";?>
	<br/>
	<div id="logout_in">
	<img src="images/logout.png" onClick="parent.window.location = './logout.php'" />
	</div>
</div>
<?php }
else{ 
?>
	<form method="POST" action="">
	<table>
	<tr>
		<td>Username:</td><td><input type="text" name="username" id="username" maxlength="20" size="10" /></td></tr>
	<tr><td>Password:</td><td><input type="password" name="password" id="password" maxlength="20" size="10" /></td></tr>
	</table>
	<div id="logout_in">
	<input type="image" src="images/loginchange.png" name="submit" />
	<?php
}

?>
</div>
	</form>

 

Any hints, tips, posts, reading, etc helps. Thanks =).

First:

$loginchange = mysql_query("UPDATE `1amyth_account` SET `loggedin` = '1' WHERE `username` = '$username'")or die(mysql_error());

 

Second:

echo out all your variables that you want to use in that query before and after the query.

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.