--- In [email protected], "siham_bakashwain" 
<[EMAIL PROTECTED]> wrote:
>
> hi all 
> i have in my form three <option>
> day , month and year 
> and i want combine the three and insert it into one field with type 
> date how i can make this ??
> please tell me 
> thanks
>

Hello,

This is a very simple example, but it should do what you need. You 
will need to enter all of the month values (1-12) into the "month" 
select menu, all of the day values (1-31) into the "day" select menu, 
and any "year(s)" you wish to display in the "year" select menu. For 
this example, I am using 11/19/2007 as the 'date string' combination 
the user selected from the select menus.

Notice in this example, the form below will post back to itself using 
$_SERVER['PHP_SELF'].

NOTE: You do not need to set the field in your database table where 
you wish to store the date to a DATE field type. Instead, use VARCHAR 
and make the field length in your database table 10 characters or 
VARCHAR(10). Do not use any default values (e.g. 0000-00-00, etc.). 

This should get you started...

<html>
<head>
<title>Date Formatting Tutorial</title>
</head>
<body>
<form name="date" action="<?php $_SERVER['PHP_SELF'] ?>" 
method="POST">
Month: <select name="month" selected><option 
value="11" />11</select><br />
Day: <select name="day" selected><option 
value="19" />19</select><br />
Year: <select name="year" selected><option 
value="2007" />2007</select><br />
<input type="submit" name="dateform" value="Submit">
</form>

<?php
if(isset($_POST['dateform']))
{
$date = $_POST['month']."/".$_POST['day']."/".$_POST['year']."";
echo $date."<br />";

$date2 = $_POST['month']."-".$_POST['day']."-".$_POST['year']."";
echo $date2."<br />";

$date3 = $_POST['year']."-".$_POST['month']."-".$_POST['day']."";
echo $date3;
}
?>
</body>
</html>

----------------------

Please refer to www.php.net/date for more guidance on how to format 
dates. Best of luck!

- William

Reply via email to