What is the problem

Discussion in 'PHP' started by anchitjindal07, Aug 30, 2009.

  1. anchitjindal07

    anchitjindal07 New Member

    Joined:
    Jul 13, 2009
    Messages:
    22
    Likes Received:
    0
    Trophy Points:
    1
    The following code creates a form. In this form one of the field is for date and the code in process.php file checks whether entered date is valid or not. But it(process.php) is not giving any output.
    HTML:
    <html>
    <title>Form</title>
    <form action="process.php" method="post">
    Name:<input type="text" name="name"size="20" ><br><br>
    
    Father's Name:<input type="text" name="fname" size="20"><br><br>
    
    Address:<textarea name="address" rows="5" cols="40"></textarea><br><br>
    Date of Birth(MM/DD/YYYY):<input type="text" name="dob"size="10"maxlength="10"><br><br>
    Course:<select name="Course">
    <option>B.Tech.
    <option>M.B.A.
    </select><br><br>
    Branch:<select name="Branch">
    <option>C.S.E.
    <option>E.C.E.
    <option>M.E.
    <option>I.T.
    <option>M.B.A.
    </select>
    <br><br>
    Batch:<input type="text" name="batch" size="9" maxlength="9"><br><br>
    Roll No.<input type="text" name="rno" size="3" maxlenght="3"><br><br>
    Univ. Reg. No.<input type="text" name="reg" size="11" maxlength="11"><br><br>
    Gender
    <br>
    <input type="radio" name="gender"value="Male">Male
    <input type="radio" name="gender"value="Male">Female<br><br>
    <input type="submit"value="Submit">
    <input type="reset">
    </html>
    Code of process.php is
    PHP:
    <?php
    $date
    =$_POST['dob'];
    $arr=split("/",$dob);
    $dd=$arr[0];
    $mm=$arr[1];
    $yy=$arr[2];
    if(
    checkdate($mm,$dd,$yy)){
    echo 
    'Valid Date';
    }else{ 
    echo 
    'Invalid Date';
    }
    ?>
     
    Last edited by a moderator: Aug 30, 2009
  2. nimesh

    nimesh New Member

    Joined:
    Apr 13, 2009
    Messages:
    769
    Likes Received:
    20
    Trophy Points:
    0
    Occupation:
    Oracle Apps Admin
    Location:
    Mumbai
    Home Page:
    http://techiethakkar.blogspot.com
    Hi Anchit,

    I don't know php but giving a shot.

    the date input format you have specified as "MM/DD/YYYY" but in the code you are checking as "DD/MM/YYYY"

    but even then you should get some output, good or bad :)
     
  3. ungalnanban

    ungalnanban New Member

    Joined:
    Feb 19, 2010
    Messages:
    45
    Likes Received:
    2
    Trophy Points:
    0
    Location:
    Chennai
    in your code split second argument is wrong .
    you need to give the $date variable.

    See the following PHP code.

    process.php
    Code:
    
    <?php
    $date=$_POST['dob'];
    
    print $date;
    $arr=split("/",[COLOR=Red]$date[/COLOR]);   
    $dd=$arr[0];
    $mm=$arr[1];
    $yy=$arr[2];
    
    if(checkdate($mm,$dd,$yy))
    {
    echo 'Valid Date';
    }
    else
    {
            echo 'Invalid Date';
    }
    ?>
    
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice