EMail address changes
Moderator: General Moderators
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
You can fix the code. Here's the logic.
- User opens a form with their information in it.
- User changes their information and submits it.
- The script checks to make sure the email address submitted is not already in the database belonging to someone else.
- If the email address exists for someone else, error out.
- If the email address does not exist, update the user record and complete the script.
4Boredom, you have the email address of the user when you populate their information.... so use that as $users_current_email
So before you run your query.... do this
note: this is just the logic, not the actual code.
So before you run your query.... do this
Code: Select all
if ($users_current_email == $users_changed_email){
// update all information
}else{
//check if email exists
}
if ($users_changed_email exists){
// throw error
}else{
//update
}This first is the edited and the second is the orig.. I think im changing it wrong?
Code: Select all
if ($users_current_email == $users_changed_email){
$sql = mysql_query("UPDATE `users` SET email_address = '{$email_address}' WHERE userid = '{$userid}' ");
$sql = mysql_query("UPDATE `basic` SET gender = '($gender)' WHERE userid = '($userid)'");
$sql = mysql_query("UPDATE `basic` SET month = '($month)' WHERE userid = '($userid)'");
$sql = mysql_query("UPDATE `basic` SET day = '($day)' WHERE userid = '($userid)'");
$sql = mysql_query("UPDATE `basic` SET year = '($year)' WHERE userid = '($userid)'");
if(!$sql){
echo 'There has been an error creating your account. Please contact the webmaster.';
echo mysql_error();
} else {
echo 'E-Mail updated! This is your new login, so remember it! '.$email_address.'';
}
}else{
$sql_email_check = mysql_query("SELECT username FROM users WHERE email_address='$email_address'");
$email_check = mysql_num_rows($sql_email_check);
$check = mysql_fetch_array($sql_email_check);
if($check['user']!=$username){
echo "Please fix the following errors: <br />";
echo "<strong>Your email address has already been used by another member in our database. Please use a different email address!<br />";
exit(); }
}
if ($users_changed_email exists){
// throw error
}else{
//update
}Code: Select all
if ($users_current_email == $users_changed_email){
// update all information
}else{
//check if email exists
}
if ($users_changed_email exists){
// throw error
}else{
//update
}I have to declare the following before I import form post variables right?
What do I do for $users_changed_email
do I do $email_address = $users_changed_email after the posting of the form?
Will this sequence work?
Code: Select all
$email_address = $users_current_emaildo I do $email_address = $users_changed_email after the posting of the form?
Will this sequence work?
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Ok, let's see if we can cover this a bit better.
When you post the form, take the posted value of the users email address they want to update to and check to see if that is in the table BUT NOT associated with the user...
When you post the form, take the posted value of the users email address they want to update to and check to see if that is in the table BUT NOT associated with the user...
Code: Select all
<?php
if (isset($_POST['check_some_filed_other_than_submit']))
{
// Form was posted
// Edit this post var to be the same name as the form field for user_email
$user_email = $_POST['email_form_field'];
// Edit this post var to be the same name as the form field for user_name
$user_name = $_POST['username_form_field'];
// Change the field names to be the what you need them to be
$sql = "SELECT COUNT(`user_id`) AS check_count
FROM `user_table`
WHERE `user_email` = '$user_email'
AND `user_name` != '$user_name'";
if (!$result = mysql_query($sql))
{
die('Could not get count to check email against: ' . mysql_error());
}
// Use the query return value ...
while ($row = mysql_fetch_array($result))
{
$check_count = $row['check_count'];
}
// ...to check if that email exists in the database already
if ($check_count <> 0)
{
// If we get here then the supplied email address exists
// in the database for some other persons record.
// That means we need to error out of the script somehow
// Pick your poison, for now I am just going to die
die('The email address you entered is already is use in the system, please enter another one');
}
else
{
// If we are here, then the email address does not exist in the system
// But it could already be in there for this user, so we need to check
// that, and if so, handle it appropriately
// But this is up to you so take care of that on your own
}
}
?>Ive been trying this several times and this is still greek to me... Please use the variables I post when you explain this... remember im a php beginner
This simply needs to allow them to click update without changing their email address because it is included on a form with other options that let them update their profile. So They can keep their current but cant duplicate an email address of someone else in the DB... someone please help with the issue this time not just with a generic answer... ive been stuck in a standstill for weeks
This simply needs to allow them to click update without changing their email address because it is included on a form with other options that let them update their profile. So They can keep their current but cant duplicate an email address of someone else in the DB... someone please help with the issue this time not just with a generic answer... ive been stuck in a standstill for weeks
Code: Select all
# grab the POST variables from the HTML form
$email_address = $_POST['email_address'];
# Any escaped characters?
$email_address = stripslashes($email_address);
# does this user already exist in the database?
$sql_email_check = mysql_query("SELECT username FROM users WHERE email_address='$email_address'");
$email_check = mysql_num_rows($sql_email_check);
$check = mysql_fetch_array($sql_email_check);
if($check['user']!=$username){
echo "Please fix the following errors: <br />";
echo "<strong>Your email address has already been used by another member in our database. Please use a different email address!<br />";
exit(); }