Solved

Insert date to mysql database problem

Posted on 2008-10-31
2
406 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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.

830 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