Solved

Insert date to mysql database problem

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

911 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

27 Experts available now in Live!

Get 1:1 Help Now