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"><option
value="11" selected />11</select><br />
Day: <select name="day"><option
value="19" selected />19</select><br />
Year: <select name="year"><option
value="2007" selected />2007</select><br />
<input type="submit" name="dateform" value="Submit">
</form>

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

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

$date3 = $_POST['year']."-".$_POST['month']."-".$_POST['day']."";
echo $date3;

$query = "INSERT INTO table_name 
(date_field1,date_field2,date_field3) VALUES 
('$date1','$date2','$date3')";
}
?>
</body>
</html>

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

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

- William

--- In [email protected], RT Web Global Net <[EMAIL PROTECTED]> 
wrote:
>
> Create a variable and combine the dates as you want them and use the
> $variable as the value for insertion
> 
> 
> 
> From: siham_bakashwain <[EMAIL PROTECTED]>
> Reply-To: <[email protected]>
> Date: Sun, 18 Nov 2007 14:25:21 -0000
> To: <[email protected]>
> Subject: [php_mysql] how combine the date ??
> 
>  
>  
>  
> 
> 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  
> 
>  
>     
> 
> 
> 
> [Non-text portions of this message have been removed]
>


Reply via email to