...

View Full Version : Registration form problem



akolyte
05-05-2009, 05:05 PM
http://ptecwebdesigners.com/bradek/Php/register.html


After completing the form online it keeps saying this, instead of the birthday.
You entered your birthday as $birthdate .




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Registration Form</title>
</head>

<body>
<!-- Script 6.1 - registure.html -->
<div> <p> Please complete this form to register:</p>
<form action="handle_reg.php" method="post">

<p>Email Address: <input type="text" name= "email" size= "30" /></p>
<p> Password: <input type="password" name= "password" size= "30" /> </p>
<p> Confirm Password <input type= "password" name="confirm" size= "20" /></p>
<p> Date Of Birth:

<select name="month">

<option value="">Month</option>
<option value="1">January</option>
<option value="2">Febuary</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">Augest</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>

<select name="day">
<option value="">Day</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>

<input type="text" name="year" value="YYYY" size="4" /></p>

<p> Favorite Color:

<select name="color">

<option value="">Pick One</option>
<option value="red">Red</option>
<option value="yellow">Yellow</option>
<option value="Green">Green</option>
<option value="Blue">blue</option>
</select></p>

<input type="submit" name="submit" value= "Register" />
</form>
</div>
</body>
</html>

,


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Registration</title>

</head>

<body>
<h2>Registration Results</h2>
<?php //Script 6.5 - handle_reg.php #4
/* This script reveives eight values from register.html
email, password, confirm, month, day, year, color, submit */

//Address error management, if you want.

// Flag variable to track success:

$okay = TRUE;

//Validate the email adress:
if (empty($_POST['email'])){
print'<p class="error">Please enter your email address.</p>';
$okay = FALSE;
}

//Validate the Password:
if(empty($_POST['password'])){
print'<p class="error">Please enter your password.</p>';
$okay = FALSE;
}
//Check the two passwords for equality:
If ($_POST['password'] !=$_POST['confirm']) {
print'<p class="error"> Your confirmed password does not match the original ppassword.</p>';
$okay= FALSE;
}

//Vallidate the birthday:
$birthday = '';

//Validate the month:
if (is_numeric($_POST['month'])){
$birthdate = $_POST['month'] . '-';
}else{
print '<p class="error"> Please select the month you were born.</p>';
$okay = FALSE;
}

//Validate the day:
if (is_numeric($_POST['day'])){
$birthdate .= $_POST['day'] . '-';
}else{
print '<p class="error"> Please select the day you were born.</p>';
$okay= FALSE;
}

//Validate the year:
if (is_numeric($_POST['year']) AND (strlen($_POST['year']) == 4) ) {

//Check that they were born before 2009.
if ($_POST['year'] >= 2009) {
print '<p class="error"> Either you entered your birth year wrong or you come from the future!</p>';
$okay = FALSE;

}else{
$birthdate= $_POST['year'];
} // End of 2nd conditional.

}else{ //ELse for 1st conditional.

print'<p c;***="error">Please enter the year you were born as four digits.</p>';
$okay = FALSE;

} //End of 1st condistional.

//Validate the color:

if($_POST['color'] = 'red') {
print '<p style="color:red;"> Red is your favorite color.</p>';
} elseif($_POST['color'] = 'yellow') {
print '<p style="color:yellow;"> Yellow is your favorite color.</p>';
} elseif($_POST['color'] = 'green') {
print '<p style="color:green;"> Green is your favorite color.</p>';
} elseif($_POST['color'] = 'blue') {
print '<p style="color:blue;"> Blue is your favorite color.</p>';
}else{ //Problem!
print '<p class="error"> Please select your favorite color.</p>';
$okay = FALSE;
}

//If there were no errors, print a success message:

if ($okay) {
print '<p> You have been successfully registered (but not really).</p>';
print '<p> You entered your birthday as $birthdate .</p>';
}
?>

</body>
</html>



Thanks for any help

Killermud
05-05-2009, 05:10 PM
Im not sure if this is what you want but at the end of your script it says :


if ($okay) {
print '<p> You have been successfully registered (but not really).</p>';
print '<p> You entered your birthday as $birthdate .</p>';
}

This is saying if variable $okay is true then execute following command, so it will say that error report im guessing. So change it to :


if (!$okay) {
print '<p> You have been successfully registered (but not really).</p>';
print '<p> You entered your birthday as $birthdate .</p>';
}

This should work

akolyte
05-05-2009, 05:18 PM
That doesn't work it ends up taking away the message.

abduraooft
05-05-2009, 05:22 PM
if($_POST['color'] = 'red') {
print '<p style="color:red;"> Red is your favorite color.</p>';
} elseif($_POST['color'] = 'yellow') {
print '<p style="color:yellow;"> Yellow is your favorite color.</p>';
} elseif($_POST['color'] = 'green') {
print '<p style="color:green;"> Green is your favorite color.</p>';
} elseif($_POST['color'] = 'blue') {
print '<p style="color:blue;"> Blue is your favorite color.</p>';
}else{ //Problem!
print '<p class="error"> Please select your favorite color.</p>';
$okay = FALSE;
}Any clues?

btw, I'd prefer to use an array for saving the error messages, instead of using the same variable $okay in all places, say

if(error in birth day)
$errors['birthday']="a message";
if(error in email)
$errors['email']="anther message";
if(error in password)
$errors['password']="some other message";
.....

if(count($errors)==0){
//sucsess
// redirect to some other page, if required,
}

......
......
echo 'The following error(s) occured, please correct them to continue....';
print_r($errors);
(just a pseudo)

Fou-Lu
05-05-2009, 06:51 PM
Im not sure if this is what you want but at the end of your script it says :


if ($okay) {
print '<p> You have been successfully registered (but not really).</p>';
print '<p> You entered your birthday as $birthdate .</p>';
}

This is saying if variable $okay is true then execute following command, so it will say that error report im guessing. So change it to :


if (!$okay) {
print '<p> You have been successfully registered (but not really).</p>';
print '<p> You entered your birthday as $birthdate .</p>';
}

This should work


Disregard this, you want to print this only if you're $okay is true, not if its false.

Anyway, the problem with you're display is you're not allowing the $birthday to parse as a PHP variable.
You're options are to surround it with double quotations, or select a new method of printing. Single quotations are interpreted as a non-parsable string literal. To use with single quotations, you'll need to break the string:


print '<p> You entered your birthday as ' . $birthdate . '.</p>';
printf("<p>You entered you're birthday as %s.</p>\n", $birthday);

// you'll need to quote my post to see this correctly, but its heredoc syntax.
print <<<BDAY
You entered you're birthday as $birthdate.
BDAY;
// etc.



abduraooft also mentioned the problem you'll run into with you're colour.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum