Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Edit Profile Page w/ Unique Email Check Problem

Status
Not open for further replies.

redzonne

Programmer
Feb 20, 2005
27
US
How can I adjust my edit profile page to only submit user information that has changed from what is already in DB for a particular user. Reason being, I have a unique email check code that stops a user from submitting an email address that is associated with a pre-exiting account. Problem is - it stops submission my profile update form, if a user chooses to update any info but the email because the form resubmits the same email address that is blocked by the unique email check code. Any suggestions?

edit profile script:

Code:
<?php
  // include validemail function for this application
  require_once('includes/validemail_fns.php');
?>
<?php

  // create short variable names
  $cfirstname=$_POST['cfirstname'];
  $cmidinitial=$_POST['cmidinitial'];
  $clastname=$_POST['clastname'];
  $cstaddress=$_POST['cstaddress'];
  $cunitnum=$_POST['cunitnum'];
  $ccity=$_POST['ccity'];
  $czip=$_POST['czip'];
  $cphone=$_POST['cphone'];
  $cemail=$_POST['cemail'];

  if (!$cfirstname || !$clastname || !$cstaddress || !$ccity || !$cstate || !$czip || !$cphone  || !$cemail)
  {
    echo '<span class=psparkred12>You have not entered all the required details.</span><br />'
            .'<span class=psparkred12>Please go back and try again.</span>';
    exit;
   }

foreach($_POST as $key => $value) {
$$key = addslashes($value);
}

  $db = mysql_pconnect('localhost', 'dbuser', 'password');

  if (!$db)
  {
    echo 'Error: Could not connect to database. Please try again later.';
    exit;
  }

  // email address not valid
  if (!valid_email($cemail))
  {
  echo '<span class=psparkred12>The email address entered is not a valid email - please go back and try again</span>';
  exit;
  }

mysql_select_db('realest1_proppost');

  //This code checks if an account already exists with entered email address
  $query4 = "SELECT cemail FROM customerindex";
  $result4 = mysql_query($query4);
  while ($row=mysql_fetch_assoc($result4)) { 
  if ($cemail == $row['cemail']) { 
  $uniqueemail = "false"; } 
  } 
  if ($uniqueemail != "false") { 
  //do nothing continue 
  } 
  else { 
  echo '<span class=psparkred12>An account with email address, <b>';
  echo $cemail; 
  echo '</b> is already exists</span><br /> <br />'; 
  exit;
  }

  mysql_select_db('realest1_proppost');
  $query2 = "UPDATE customerindex SET cfirstname='$cfirstname', clastname='$clastname', cmidinitial='$cmidinitial', cstaddress='$cstaddress', cunitnum='$cunitnum', ccity='$ccity', czip='$czip', cphone='$cphone', cfax='$cfax', cemail='$cemail' WHERE login='$login'";
  $result2 = mysql_query($query2) or die(mysql_error());

if ($result2)
{
     echo '<span class=p2><b>Profile Updated</b></span><br /><br />';
     echo '<span class=psparkblu12><b>';
     echo $myrow["login"];
     echo '</b> You have successful updated your user profile for your property posting account</span><br /><br />';
     echo '<a class=pmidblu href="proppost_controlpanel.php">Click here to return to Property Post Control Panel</br></a>';
}
?>

The Journey of a Thousand Miles Begins with the First Step...
 
For such updates I would set the original data into a session variable. Upon submission I'd compare the content of the POST data to the session vars and only put the changed values into the update statement.
e-mail addresses are not a good way of indexing customer information. You should introduce a numeric, autoincrementing ID that can be used to acces customer info and update it. Updating by unique ID does no create a problem.
e-mail addresses also need to be made unifom - all lower case for example.
 
I am actually not using email addresses as a way to index customers. I actually use unique user chosen login to index customers.

Email address are submit to my DB is unique format with the below code:
Code:
<?
function valid_email($address)
{
  //check an email address is possibly valid
  if (ereg('^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$', $address))
     return true;
  else
     return false;
}
?>

The Journey of a Thousand Miles Begins with the First Step...
 
I changed:

"SELECT cemail FROM customerindex"

to:

"SELECT cemail FROM customerindex where login <> '$login'"

This returns all the email addresses apart from their's

The Journey of a Thousand Miles Begins with the First Step...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top