0

Possible Duplicate:
GET URL parameter in PHP

(Mind you I am fairly new to PHP and still learning) I have form:

<form name="checkingEmail">
        E-Mail: <input type="text" name="email1" />
        <br />
        Retype E-Mail: <input type="text" name="email2" />
        <br />
        <input type="button" value="Submit" onClick="checkEmail()">
    </form>

and I want to take the values from the User Input and do a simple If...Else statement after they hit "Submit"

PHP:

<?php
$email1 = blah //Value from email1 input form here;
$email2 = blah //Value from email2 input form here;
function checkEmail()
{
global $email1, $email2;
if($email1==$email2)
{
//Some Code Here
}
else
{
echo "Make sure your E-Mail addresses match";
}
}
?>
Community
  • 1
  • 1
  • 1
    I can't believe the PHP tutorial you're learning from doesn't explain this. It's PHP 101. – Barmar Jan 17 '13 at 01:35

3 Answers3

0
$email1 = $_GET['email1'];
$email2 = $_GET['email2'];

Then make sure that you call the checkEmail() function.

ixchi
  • 2,349
  • 2
  • 26
  • 23
0

You should be using the GET or POST variable on your form .. so include the method attribute in your form element:

<form method="get">

And then use GET or POST for a more secure approach ... the form input isn't shown in the URL when using the POST method.

You can use either like:

$email1 = $_POST['email1'];
$email2 = $_POST['email2'];
Adrift
  • 58,167
  • 12
  • 92
  • 90
0

You should also specify the sending method: POST or GET inside the form html:

-->GET

HTML:

    <form name="checkingEmail" method="get">

PHP:

    $email1 = $_GET['email1'];

-->POST

HTML:

    <form name="checkingEmail" method="post">

PHP:

    $email1 = $_POST['email1'];

Or you can check which type has a field passed.

HTML:

    <input type='hidden' name='check' />

PHP:

    if(isset($_POST['check'])) {
        // Post method
      } elseif(isset($_GET['check'])) {
        // Get method
      } else {
        // failure
      } 
Bryan
  • 51
  • 5