Jump to content

cant update user details in a session


nelquintin

Recommended Posts

i have a problem where i can only update the first name in my database details no matter whose logged in.here is the code.Any suggestions?

if(isset($_POST['editdetail']))

{

$current = trim($_POST['current']);

$new = trim($_POST['new']);

$confirm = trim($_POST['confirm']);

$price = trim($_POST['price']);

$area = trim($_POST['area']);

$description = trim($_POST['description']);

 

$query = mysql_query("SELECT * FROM Users WHERE username = '$current' LIMIT 1") or die(mysql_error());

$do = mysql_query("UPDATE Users SET price = '$price'  LIMIT 1") or die(mysql_error());

$dotwo = mysql_query("UPDATE Users SET area = '$area' LIMIT 1") or die(mysql_error());

$dothree = mysql_query("UPDATE Users SET description = '$description' LIMIT 1") or die(mysql_error());

Link to comment
https://forums.phpfreaks.com/topic/37160-cant-update-user-details-in-a-session/
Share on other sites

You aren't specifying a "where clause" in your updates. Each update you're performing is overwriting every row in the database. Example:

 

if you have 5 rows in the table, and you perform an update WITHOUT supplying a "where" clause, each row is updated with the information provided. However, you are saying "LIMIT 1" which means only update the first row out of all rows (not the row you want it to find).

 

so. your $do should be:

 

$do = mysql_query("UPDATE Users SET price = '$price' WHERE username='$current' LIMIT 1") or die(mysql_error());

 

You're also performing 3 updates when it could just be one. Like this:

 

$do = mysql_query("UPDATE Users SET price = '$price',area='$area',description='$description' WHERE username='$current' LIMIT 1") or die(mysql_error());

 

Enjoy~

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.