Solved

Insert date to mysql database problem

Posted on 2008-10-31
2
399 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
Comment Utility
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
Comment Utility
Thanks!!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now