nelquintin Posted February 5, 2007 Share Posted February 5, 2007 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 More sharing options...
Xinil Posted February 5, 2007 Share Posted February 5, 2007 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~ Link to comment https://forums.phpfreaks.com/topic/37160-cant-update-user-details-in-a-session/#findComment-177534 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.