Jump to content

[SOLVED] Form date insert in mysql database


Marcos01

Recommended Posts

Hi all,

 

I would like to select a date and insert the date into the database.

 

The date form has 3 dropdown boxes. Days, months and years.

 

Can you help me with the code:

 

This is what I have so far:

 

The form:

 

<form id="form1" name="form1" method="post" action="">
  <label>
  Dag:
  <select name="day" id="day">
  <option value="01">1</option>
</select>
Month:
<select name="month" id=month">
<option> value="01"> id="1"</option>
</select>
Year:
<select name="year" id=year">
<option> value="2008"> id="2008"</option>
</select>

 

PHP:

 

<?php
$date =  $year $month $day

?>

<?php 
$query ="INSERT INTO trainingsdata (date)	
		values({$date})";
if (mysql_query($query, $connection)){
header("location: content.php");
exit;	
}else{
echo "data has not been added to database";
echo .mysql_error() .;
}

You have a problem here:

<select name="year" id=year">
<option> value="2008"> id="2008"</option>

 

Do it like this:

 

<select name="year" id=year">
<option value="" selected="selected"></option>
<option value="2008" >2008</option>

 

Apply the same to month and day.

 

Was originaly working????

Thanks Mchl and budimir.

 

I corrected the typing error and added:

 

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

 

With a little change from yours Mchl and it worked!

 

<?php
$datum = $_POST['year']."-".$_POST['month']."-".$_POST['day'];

?>

<?php 
$query ="INSERT INTO trainingsdata (date)	
		values({$date})";
if (mysql_query($query, $connection)){
header("location: content.php");
exit;	
}else{
echo "data has not been added to database";
echo .mysql_error() .;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.