Hello I am running a server side database to process input from an android phone. I have two functions one to store the user information and one to update their location.
The second one to store location I cannot get to work.
/**
* Storing new user
* returns user details
*/
public function storeUser($name, $email, $password) {
$uuid = uniqid('', true);
$hash = $this->hashSSHA($password);
$encrypted_password = $hash["encrypted"]; // encrypted password
$salt = $hash["salt"]; // salt
$result = mysql_query("INSERT INTO users(unique_id, name, email, encrypted_password, salt, created_at) VALUES('$uuid', '$name', '$email', '$encrypted_password', '$salt', NOW())");
// check for successful store
if ($result) {
// get user details
$uid = mysql_insert_id(); // last inserted id
$result = mysql_query("SELECT * FROM users WHERE uid = $uid");
// return user details
return mysql_fetch_array($result);
} else {
return false;
}
}
/**
* Updating a users
* location
*/
public function updateLocation($email, $location) {
$uuid = uniqid('', true);
$result = mysql_query("UPDATE users SET location='$location' WHERE email='$email' NOW())");
// check for successful store
if ($result) {
// get user details
$uid = mysql_insert_id(); // last inserted id
$result = mysql_query("SELECT * FROM users WHERE email = $email");
// return user details
return mysql_fetch_array($result);
} else {
return false;
}
}
Any help greatly appreciated.
Thanks
In looking at your update query $result = mysql_query("UPDATE users SET location='$location' WHERE email='$email' NOW())");
You appear to be missing part of it. You need to tell it what needs to be set to NOW(), perhaps updated_at, "UPDATE users SET location='$location', updated_at = NOW() WHERE email='$email'"
似乎你有一个错误:“ WHERE email='$email' NOW())
”into“ created_at='NOW()' WHERE email='$email'
”
在SQL的末尾有一个额外的NOW()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.