Jump to content

Recommended Posts

I have an update form where users can update their info.

 

If they update their email address, I want "to do" something.

 

For example:

 

if(isset($email) )
{
do something
}

 

However the isset function won't work in my case because $email is always NOT NULL so it will always perform this action which won't be necessarily.

 

What  function do I use to check if $email was changed?

When the form is submitted, check if the email isn't empty (via $_POST or $_GET) and if not, update the data in database. There's no need to compare the form value with the actual value from database, because if the email isn't empty, it is supposed to be changed.

 

<?php
$email = trim($_POST['email']);
if ($email != '') {
     $results = mysql_query("UPDATE users SET email='$email' WHERE user_id=10");
}
?>

 

Hope I got it right, anyway.

When the form is submitted, check if the email isn't empty (via $_POST or $_GET) and if not, update the data in database. There's no need to compare the form value with the actual value from database, because if the email isn't empty, it is supposed to be changed.

 

<?php
$email = trim($_POST['email']);
if ($email != '') {
     $results = mysql_query("UPDATE users SET email='$email' WHERE user_id=10");
}
?>

 

Hope I got it right, anyway.

 

the empy function is better

email will always be not empty.

 

For example, let's say John wants to update his email address.

 

The update form loads john@somewhere.com into the form but then he changes it to johnny@somewhere.com. If this is the case then I'll need to update the members database as well with his new email address. Sure I can always perform this action and override it everytime but I don't think it's necessarily?

Or maybe just not have the form fetch their email address into the email text field and if they fill this field in then I'll update the members database as well? Then I can use the isset function and let them know only to fill in this textbox if they want to update their email address and display their old one below it.

If the value of a field value in the UPDATE query is the same as what's in the field already, MySQL won't do anything with it anyhow.

 

http://dev.mysql.com/doc/refman/5.0/en/update.html

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.