Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    May 2009
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Year want display on php print page.

    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:



    Code:
    <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>
    Code:
    <?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";
    
    ?>
    Last edited by dj1mitch; 05-02-2009 at 03:48 AM. Reason: Adding Form Code

  • #2
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    Hi can we see the form
    You can not say you know how to do something, until you can teach it to someone else.

  • #3
    New Coder
    Join Date
    Jan 2009
    Posts
    91
    Thanks
    17
    Thanked 1 Time in 1 Post
    First you have:

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

    two times. Second should be:

    PHP Code:
    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?

  • #4
    New to the CF scene
    Join Date
    May 2009
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Code:
    <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>
    Last edited by dj1mitch; 05-02-2009 at 04:20 AM.

  • #5
    New to the CF scene
    Join Date
    May 2009
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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?

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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 [code][/code] tags.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • Users who have thanked Fou-Lu for this post:

    dj1mitch (05-02-2009)

  • #7
    New to the CF scene
    Join Date
    May 2009
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Wow! Thanks Fou-Lu, you are great.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •