psychohagis Posted January 4, 2007 Share Posted January 4, 2007 I have a page which updates profile information sent from a form. Im having a problem. I couldn't get it to work sending a single statement so I thought I'd try sending a sql statement for every column I needed to update. This doesn't present me with any errors, but it does not update my database. This is what I've got at the moment, whats a better way, and a way that actually works of doing this:[quote]$sql = "UPDATE users SET firstname='$firstname' WHERE id='$userid'";if (@mysql_query($sql)) {echo 'fine';} else {exit('<p>Error performing update: ' . mysql_error() . '</p>\n');}$sql2 = "UPDATE users SET surname='$surname' WHERE id='$userid'";if (@mysql_query($sql2)) {echo 'fine';} else {exit('<p>Error performing update: ' . mysql_error() . '</p>\n');}$sql3 = "UPDATE users SET email='$email' WHERE id='$userid'";if (@mysql_query($sql3)) {echo 'fine';} else {exit('<p>Error performing update: ' . mysql_error() . '</p>\n');}$sql4 = "UPDATE users SET location='$location' WHERE id='$userid'";if (@mysql_query($sql4)) {echo 'fine';} else {exit('<p>Error performing update: ' . mysql_error() . '</p>\n');}$sql5 = "UPDATE users SET webpage='$webpage' WHERE id='$userid'";if (@mysql_query($sql5)) {echo 'fine';} else {exit('<p>Error performing update: ' . mysql_error() . '</p>\n');}$sql6 = "UPDATE users SET about='$about' WHERE id='$userid'";if (@mysql_query($sql6)) {echo 'fine';} else {exit('<p>Error performing update: ' . mysql_error() . '</p>\n');}[/quote]Can anyone help? Quote Link to comment Share on other sites More sharing options...
artacus Posted January 4, 2007 Share Posted January 4, 2007 Why wouldn't the single statement work?My guess is that you are working off of old code or an old example when REGISTER_GLOBALS was turned on. Look for your variables in $_REQUEST['first_name'] instead.Try:[code]$sql = "UPDATE users SET first_name = '$first_name', last_name = '$last_name', etc... "WHERE id='$user_id'";[/code] Quote Link to comment Share on other sites More sharing options...
psychohagis Posted January 4, 2007 Author Share Posted January 4, 2007 no. I wrote this code myself. I am certain that the variables are named correctly Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.