Solved

Insert date to mysql database problem

Posted on 2008-10-31
2
403 Views
Last Modified: 2013-12-13
I have simple php form where user input date format dd.mm.yyyy and then that info goes to action page which in turn uses a sql statement to send the info to a mysql table. One of the fields is a date field and  the field has 00.00.0000 in it? And my sql query shows only last inserted data? Only one row?

Every other data from a form goes nicely to database.
form (date input)
<input type="text" name="aika">
 
action page									  <?php
$host = "sql";
$username="x";
$password="x";
$database="x";
 
mysql_connect(sql,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
 
$aika = strftime("%dd.%mm.%YYYY", strtotime($_POST['aika']));
$kaupunki=$_POST['kaupunki'];
$maa=$_POST['maa'];
$esiintymispaikka=$_POST['esiintymispaikka'];
 
$query = "INSERT INTO kiertue (aika, kaupunki, maa, esiintymispaikka) VALUES
('$aika','$kaupunki','$maa','$esiintymispaikka')" ;mysql_query($query);
 
mysql_close();
?>

Open in new window

0
Comment
Question by:tikkanen
2 Comments
 
LVL 34

Accepted Solution

by:
Beverley Portlock earned 250 total points
ID: 22851836
To insert into a MySQL table's date field, the date must be in the format YYYY-MM-DD so try this (UNTESTED) code


$aika = strftime("%dd.%mm.%YYYY", strtotime($_POST['aika']));
$aika2 = date("Y-m-d",  strtotime($_POST['aika']) );

$kaupunki=$_POST['kaupunki'];
$maa=$_POST['maa'];
$esiintymispaikka=$_POST['esiintymispaikka'];
 
$query = "INSERT INTO kiertue (aika, kaupunki, maa, esiintymispaikka) VALUES
('$aika2','$kaupunki','$maa','$esiintymispaikka')" ;mysql_query($query);
 
0
 

Author Closing Comment

by:tikkanen
ID: 31512101
Thanks!!
0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to count in a table in php 22 36
Why do people dis php? 5 51
preventing spam with mailto 22 36
PHP Syntax Error 4 27
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question