Easy question, except I don't know how to do it. I want to ask for user's email address and then have them confirm it. How do I use php to check to make sure the confirmation matches the first email address entered?

Thanks in advance!
~Amy

Recommended Answers

All 6 Replies

<form id="form1" name="form1" method="post" action="">
  <label>Email
  <input type="text" name="email1" />
  </label>
  <p>
    <label>Confirm Email
    <input type="text" name="email2" />
    </label>
  </p>
</form>

<?php

$email1=email1;
$email2=email2;

if ($email1 == $email2)
  echo "Emails are  the same!"; 
else
  echo "Emails are Incorrect!"; 
?>

I'm not exactly crash hot at PHP so im not 100% sure thats correct, but i thought i'd give it a shot.

Should work, but you might want to use this for strings

if you don't care about case use strcasecmp instead strcmp

if equal they will return 0

if(strcmp($email1, $email2)==0){
  echo "Emails are same";
} else {
echo "Emails are Incorrect";
}

And you probably want to declare the E-mail variables correctly. Also, paragraph tags within a form used in that way aren't exactly semantically correct. It's acceptable to use <br /> tags right after the labels or CSS floats if you want to help style your form rather than paragraph tags, as form elements aren't exactly paragraphs. Oh, and the name attribute on a form tag is not valid if you're using XHTML.

I'm a neat freak. :/

<form id="form1" method="post" action="">
 <fieldset>
  <legend>E-mail</legend>
  <label for="email1">Email</label>
  <input type="text" name="email1" />
  <label for="email2">Confirm Email</label>
  <input type="text" name="email2" />
 </fieldset>
</form>

<?php
$email1 = $_POST['email1'];
$email2 = $_POST['email2'];

if (strcmp($email1, $email2) == 0) {
 echo "Emails are  the same!"; 
} else {
 echo "Emails are not the same!"; 
}
?>

Easy enough!
Thanks to you all!
~Amy

I made a ton of edits to my post. I kept noticing errors, lol. I've been doing this too long. :X

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.