简体   繁体   中英

Updating a row with query language, mysql, php

I have a basic question for you experts,

I want to update a row in mysql database by using the User_Id of an entry. I created User_Id as auto increment, primary key. Now for the last user I calculated its necessary variables, now I want to add that variable to the last user's necessary column through its User_id.

The name of the variable I want to add is $improvement. I wrote the code below, however I dont now how to do that depending on its User_Id.

$sql = "
UPDATE users 
SET Improvement='$improvement'
WHERE ... )
";  

mysql_query($sql, $accounts);

I dont know what to write to the "..." part in the code. Please give me feedback if you see a problem in my question. I can give my table if you need.

mysql updating last inserted id

I guess I found the answer in that link:

$sql = "
UPDATE users 
SET Improvement='$improvement'
WHERE User_id = LAST_INSERT_ID() )
";  

However I am not sure if "SET Improvement='$improvement'" part is the correct syntax

If your user_id is primary index then you can use

$sql = " UPDATE users SET Improvement='$improvement' order by user_id DESC limit 1 ) ";

mysql_query($sql, $accounts);

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM