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
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.