Jump to content

Duplicate E-Mail Address


slionheart

Recommended Posts

Hey everyone how's it going? First I want to start out and mention that I'm a total noob and I'm using Dreamweaver 8. Now here is my situation. I built a form and it's submitting to information to the database, but I want to make sure that someone doesn't use the same email address, how do I validate that and send back that the email address has already been used so there are no duplicates. Thank you for your time, my code is posted below.




<form action="<?php echo $editFormAction; ?>" method="POST" name="form1" id="form1" >
      <table width="453" border="0" cellpadding="5" cellspacing="1" bgcolor="#59AD00" class="plaintext">
        <tr>
          <td height="23" bgcolor="#99CC00" class="SectionTab"><b> Contact Information:</b></td>
          <td valign="top" class="sectiontab">&nbsp;</td>
        </tr>
        <tr>
          <td width="160" nowrap="nowrap" bgcolor="#99CC00" class="AppLeft">Name:</td>
          <td width="270" nowrap="nowrap" bgcolor="#FFFFFF" class="AppRight"><font color="#333333">First
              <input name="FirstName" style="WIDTH: 100px;" maxlength="50" />
            Last
            <input name="LastName" style="WIDTH: 100px;" maxlength="50" />
          </font></td>
        </tr>
        <tr>
          <td nowrap="nowrap" bgcolor="#99CC00" class="AppLeft">Street Address:</td>
          <td nowrap="nowrap" bgcolor="#FFFFFF" class="AppRight"><input name="Street" id="Street" style="WIDTH: 250px;" maxlength="50" /></td>
        </tr>
        <tr>
          <td nowrap="nowrap" bgcolor="#99CC00" class="AppLeft">City, State &amp; Zip</td>
          <td nowrap="nowrap" bgcolor="#FFFFFF" class="AppRight"><input name="City" id="City" style="WIDTH: 100px;" maxlength="50" />
              <select name="State" id="State">
                <option value="AL">AL</option>
                <option value="AK">AK</option>
                <option value="AZ">AZ</option>
                <option value="AR">AR</option>
                <option value="CA">CA</option>
                <option value="CO">CO</option>
                <option value="CT">CT</option>
                <option value="DE">DE</option>
                <option value="DC">DC</option>
                <option value="FL">FL</option>
                <option value="GA">GA</option>
                <option value="HI">HI</option>
                <option value="ID">ID</option>
                <option value="IL">IL</option>
                <option value="IN">IN</option>
                <option value="IA">IA</option>
                <option value="KS">KS</option>
                <option value="KY">KY</option>
                <option value="LA">LA</option>
                <option value="ME">ME</option>
                <option value="MD">MD</option>
                <option value="MA">MA</option>
                <option value="MI">MI</option>
                <option value="MN">MN</option>
                <option value="MS">MS</option>
                <option value="MO">MO</option>
                <option value="MT">MT</option>
                <option value="NE">NE</option>
                <option value="NV">NV</option>
                <option value="NJ">NJ</option>
                <option value="NM">NM</option>
                <option value="NY">NY</option>
                <option value="NC">NC</option>
                <option value="ND">ND</option>
                <option value="OH">OH</option>
                <option value="OK">OK</option>
                <option value="OR">OR</option>
                <option value="PA">PA</option>
                <option value="RI">RI</option>
                <option value="SC">SC</option>
                <option value="SD">SD</option>
                <option value="TN">TN</option>
                <option value="TX">TX</option>
                <option value="UT">UT</option>
                <option value="VA">VA</option>
                <option value="VT">VT</option>
                <option value="WA">WA</option>
                <option value="WV">WV</option>
                <option value="WI">WI</option>
                <option value="WY">WY</option>
              </select>
              <input name="Zip" id="Zip" style="WIDTH: 50px;" maxlength="5" />          </td>
        </tr>
        <tr>
          <td nowrap="nowrap" bgcolor="#99CC00" class="AppLeft">E-Mail:</td>
          <td nowrap="nowrap" bgcolor="#FFFFFF" class="AppRight"><input name="EMail" id="EMail" size="35" maxlength="20" /></td>
        </tr>
        <tr>
          <td nowrap="nowrap" bgcolor="#99CC00" class="AppLeft"> Phone:</td>
          <td nowrap="nowrap" bgcolor="#FFFFFF" class="AppRight"><input name="Phone" id="Phone" style="WIDTH: 100px;" maxlength="20" /></td>
        </tr>
        <tr>
          <td nowrap="nowrap" bgcolor="#99CC00" class="AppLeft">Cell Phone:</td>
          <td nowrap="nowrap" bgcolor="#FFFFFF" class="AppRight"><input name="CellPhone" id="CellPhone" style="WIDTH: 100px;" maxlength="20" /></td>
        </tr>
        <tr>
          <td nowrap="nowrap" bgcolor="#99CC00" class="AppLeft">Best Time to Call:</td>
          <td nowrap="nowrap" bgcolor="#FFFFFF" class="AppRight" style="width: 150px;"><select name="BestTimeToCall">
              <option value="8am - 10am">8am - 10am</option>
              <option value="10am - 12 noon">10am - 12 noon</option>
              <option value="12noon - 2pm">12noon - 2pm</option>
              <option value="2pm - 4pm">2pm - 4pm</option>
              <option value="4pm - 6pm">4pm - 6pm</option>
              <option value="6pm - 8pm">6pm - 8pm</option>
            </select>          </td>
        </tr>
        <tr>
          <td colspan="2" nowrap="nowrap" bgcolor="#FFFFFF" class="AppLeft"><div align="center"><font color="#333333">Time Zone: </font>           
                <select name="TimeZone" id="TimeZone">
                  <option>(GMT -10:00) Hawaii</option>
                  <option>(GMT -9:00) Alaska</option>
                  <option>(GMT -8:00) Pacific Time (US &amp; Canada)</option>
                  <option>(GMT -7:00) Mountain Time (US &amp; Canada)</option>
                  <option selected="selected">(GMT -6:00) Central Time (US &amp; Canada), Mexico City</option>
                  <option>(GMT -5:00) Eastern Time (US &amp; Canada), Bogota, Lima</option>
                </select>
          </div></td>
          </tr>
        <tr>
          <td nowrap="nowrap" bgcolor="#99CC00" class="AppLeft"><p>Position interested in </p>
              <p><i>ex. customer service, </i></p>
              <p><i>tech support, </i></p>
            <p><i>Admin assistant</i></p></td>
          <td nowrap="nowrap" bgcolor="#FFFFFF" class="AppRight" style="width: 150px;"><input name="Posistion_Interested" id="Posistion_Interested" maxlength="40" /></td>
        </tr>
        <tr>
          <td valign="top" nowrap="nowrap" bgcolor="#99CC00" class="AppLeft">Notes</td>
          <td nowrap="nowrap" bgcolor="#FFFFFF" class="AppRight" style="width: 150px;"><textarea name="Notes" cols="35" rows="5" id="Notes"></textarea></td>
        </tr>
        <tr>
          <td nowrap="nowrap" bgcolor="#99CC00" class="AppLeft"><p>Salary preference</p>
              <p><i>ex. 8,9,10/Hr or Annual</i></p></td>
          <td nowrap="nowrap" bgcolor="#FFFFFF" class="AppRight" style="width: 150px;"><span class="AppRight" style="width: 150px;">
            <input name="Salary" id="Salary" style="WIDTH: 100px;" maxlength="20" />
          </span></td>
        </tr>
        <tr>
          <td nowrap="nowrap" bgcolor="#99CC00" class="AppLeft">Highest level of education </td>
          <td nowrap="nowrap" bgcolor="#FFFFFF" class="AppRight" style="width: 150px;"><select name="LevelEducation" id="LevelEducation">
              <option value="GED">GED</option>
              <option value="High School">High School</option>
              <option value="Some College">Some College</option>
              <option value="Bachelors">Bachelors</option>
          </select></td>
        </tr>
        <tr>
          <td nowrap="nowrap" bgcolor="#99CC00" class="AppLeft">Currently in school </td>
          <td nowrap="nowrap" bgcolor="#FFFFFF" class="AppRight" style="width: 150px;"><span class="AppRight" style="width: 150px;">
            <select name="CurrentlyInSchool" id="CurrentlyInSchool">
              <option value="Yes">Yes</option>
              <option value="No">No</option>
            </select>
          </span></td>
        </tr>
        <tr>
          <td nowrap="nowrap" bgcolor="#99CC00"><p>Willing to go back to school </p>
            <p><i><font size="1">(Most employers are willing to  hire </font></i></p>
            <p><i><font size="1">applicants that are in school or </font></i></p>
            <p><i><font size="1">willing to further their education </font></i></p>
            <p><i><font size="1">at  some point.)</font></i></p></td>
          <td nowrap="nowrap" bgcolor="#FFFFFF" class="AppRight" style="width: 150px;"><span class="AppRight" style="width: 150px;">
            <select name="GoBackToSchool" id="GoBackToSchool">
              <option value="Yes">Yes</option>
              <option value="No">No</option>
            </select>
          </span></td>
        </tr>

        <tr>
          <td colspan="2" align="center" valign="center" bgcolor="#99CC00"><span class="AppLeft">
            <input name="Date" type="hidden" id="Date" value="<?php echo date("Y/m/d"); ?>" />
          </span>
            <div align="center">
              <input name="submit" type="submit" value="Submit Information" />
              <br />
              <FONT color="navy" size="1"> <u></td>
        </tr>
      </table>
      <input type="hidden" name="MM_insert" value="form1">
    </form>
Link to comment
Share on other sites

In your Insert Query, you must first Select if the email address is in the database:

$query = "SELECT * FROM yourtable WHRE email_field = '{$_POST['EMail']}' ";
$result = mysql_query($query) or die(mysql_error());
$num = mysql_num_rows($result);

if ($num == 0) {
//Your Insert Query Here
}

Hope this helps! :)
Link to comment
Share on other sites

mitzleah has a good method of checking from the script side, but even before that, you should have a unique constraint on your database column where you're storing the email addresses so that you can back yourself up. basically, when you create your database table, simply add the word UNIQUE at the end of the row where you define your email address field:
[code]
CREATE TABLE myTable(
-- other column definitions here
email_address varchar(100) UNIQUE,
-- other column definitions here
);
[/code]

then, a script like was mentioned above is great:
[code]
<?php
$email = $_POST['email'];
$sql = mysql_query("SELECT * FROM table WHERE email_address = '$email'");
if (mysql_num_rows($sql) > 0) {
  // email already exists. show error message here
} else {
  // passed! insert record here
}
?>
[/code]
Link to comment
Share on other sites

I would do what [b]obsidian[/b] said, make it UNIQUE, but I wouldn't test for it, I would just try to do the insert and catch the ER_DUP_KEY if it's thrown! If it is thrown return the form back to the user!

[code]$out = false;
mysql_query() or check_err ($out /*returned by ref */, mysql_error());

if ( $out )
{
// return the form error
}[/code]

me!
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.