Jump to content

[SOLVED] Problems with an update query


kryppienation

Recommended Posts

I am having problems, for some reason the code below is not changing the db value, i've tried a few things and still can't get it to change. Is there anyone around who can figure out and let me know what the problem is here... The echo's work fine, displaying the username and the number 1 but for some reason the database value never changes from 0 to 1.

 

 

here is the portion of code not working:

 

$usertologin = $_SESSION["s_username"];
			$loggedinid = "1";

			echo $usertologin;
			echo $loggedinid;


			$setloggedinsql = 'update knusers set online = ".$loggedinid." where username = ".$usertologin."';
			DB::query($setloggedinsql, "Validating user creditials");

 

 

Here is the entire code:

 

 

<?php

// set your infomation.
include('db.php');
// connect to the mysql database server.
DB::connect($DB_database);

session_start();

// connect to the mysql database server.
if ($_POST['username']) {
	// did they supply a password and username
	$username=mysql_real_escape_string($_POST['username']);
	$password=mysql_real_escape_string($_POST['password']);
	if ($password == NULL) {
		$nopass = "A password was not supplied";
	} else {
		$checkuser = "SELECT username, wid, aid, str, def, currency, password FROM knusers WHERE username = '$username'";
		$checkuser_result = DB::query($checkuser, "Validating user creditials");
		$checkuser_data = mysql_fetch_array($checkuser_result);


		if ($checkuser_data['password'] != $password) {
			$loginbad = "The supplied login is incorrect, Please check your password";
		} else {
			$_SESSION["s_username"] = $checkuser_data['username'];
			$_SESSION["s_weapon"] = $checkuser_data['wid'];
			$_SESSION["s_armor"] = $checkuser_data['aid'];
			$_SESSION["s_str"] = $checkuser_data['str'];
			$_SESSION["s_def"] = $checkuser_data['def'];
			$_SESSION["s_currency"] = $checkuser_data['currency'];
			$_SESSION["s_ipaddress"] = $_SERVER['REMOTE_ADDR'];
                $_SESSION["s_lastlogin"] = date('l jS \of F Y h:i:s A');





			if ($_POST["returnTo"] != null) {
				//header("location: ../index.php");
			}
			$usertologin = $_SESSION["s_username"];
			$loggedinid = "1";

			echo $usertologin;
			echo $loggedinid;


			$setloggedinsql = 'update knusers set online = ".$loggedinid." where username = ".$usertologin."';
			DB::query($setloggedinsql, "Validating user creditials");
			//header("location: ../index.php");


		}
	}
}
?>

 

Any help will be greatly appriciated. Thank you.

Link to comment
https://forums.phpfreaks.com/topic/177032-solved-problems-with-an-update-query/
Share on other sites

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.