...

View Full Version : Year want display on php print page.



dj1mitch
05-02-2009, 02:29 AM
I am creating a form and using if (is_numeric ($year)) {
$birthdate .= $year;
}. To validate the year, the month and date displays, but the year is not showing.
Please help!
Here is the code I am using:




<form action="registration.php" method="post">

<p>First Name: <input typoe="text" name="first_name" size="20" /></p>

<p>Last Name: <input type="text" name="last_name" size="20" /></p>

<p>Email Address: <input type="text" name="email" size="20" /></p>

<p>Password: <input type="password" name="password" size="20" /></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">February</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">August</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="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</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</option>
<option value="red">red</option>
<option value="yellow">yellow</option>
<option value="green">green</option>
<option value="blue">blue</option>
</select></p>

<p><input type="submit" name="submit" value="Register" /></p>


</form>

<?php //

// Address error handling.
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~ E_NOTICE);

// In case register_globals is disabled
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$password = $_POST['password'];
$confirm = $_POST['confirm'];
$month = $_POST['month'];
$day = $_POST['day'];
$year = $_POST['year'];
$color = $_POST['color'];

print '<p>Registration Results:</p>';

// Validate Form input.
if (empty ($first_name)) {
print '<p>Please enter your first name.</p>';
}

if (empty ($first_name)) {
print '<p>Please enter your last name.</p>';
}

if (empty ($email)) {
print '<p>Please enter your email address.</p>';
}

if (empty ($password)) {
print '<p>Please enter your password</p>';
}

// Validate month, day and year.
if (is_numeric ($month)) {
$birthdate = $month . '-';
} else {
print '<p>Please select the month you were born.</p>';
}

if (is_numeric ($day)) {
$birthdate .= $day . '-';
} else {
print '<p>Please select the day you were born.</p>';
}

if (is_numeric ($year)) {
$birthdate .= $year;
} else {
print '<p>Please enter the year you were born as four digits.</p>';
}

print "You entered your birthday as $birthdate";

?>

timgolding
05-02-2009, 03:03 AM
Hi can we see the form

Hayyel
05-02-2009, 03:09 AM
First you have:


if (empty ($first_name)) {
print '<p>Please enter your last name.</p>';
}

two times. Second should be:


if (empty ($last_name)) {
print '<p>Please enter your last name.</p>';
}

That code seems to work for me. Perhaps its the form not passing the year data?

dj1mitch
05-02-2009, 04:49 AM
<form action="registration.php" method="post">

<p>First Name: <input typoe="text" name="first_name" size="20" /></p>

<p>Last Name: <input type="text" name="last_name" size="20" /></p>

<p>Email Address: <input type="text" name="email" size="20" /></p>

<p>Password: <input type="password" name="password" size="20" /></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">February</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">August</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="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</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</option>
<option value="red">red</option>
<option value="yellow">yellow</option>
<option value="green">green</option>
<option value="blue">blue</option>
</select></p>

<p><input type="submit" name="submit" value="Register" /></p>


</form>

dj1mitch
05-02-2009, 04:56 AM
Sorry guys for posted the form code incorrectly. I am new on this forum and working with forum posting. Also, just learning PHP. Please forgive me?

Fou-Lu
05-02-2009, 05:02 AM
Problem right here: <input type="text" name"year" value="YYYY" size="4" />. That should be name="year".

BTW, you can edit you're post and wrap the form in
tags.

dj1mitch
05-02-2009, 05:07 AM
Wow! Thanks Fou-Lu, you are great.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum