Jump to content

[SOLVED] update problems


psychohagis

Recommended Posts

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?
Link to comment
https://forums.phpfreaks.com/topic/32886-solved-update-problems/
Share on other sites

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]

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.