Jump to content

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() .;
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.