Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

How do I add a "date" value to MySQL table using PHP?

How do I add a "date" value to MySQL table using PHP?

How do I add a "date" value to MySQL table using PHP?

Hello everyone,
Table "hourShifts" contains a field names: "shiftdate". Please see table structure attached in annex a.

My code goes like this :


<?php //MyINITIAL.PHP 
$MyHOST = 'localhost'; 
$MyUSER = 'aaa'; 
$MyPASS = 'bbb'; 
$MyDB = 'test'; 


<?php //MyLOGIN.PHP 


<?php // 222.php 
$yosDAT = get_post($MyCONNECTION,'MyDAT'); 
$MyQUERY = "INSERT INTO hourShifts(shiftdate) VALUES($yosDAT)"; 
if(!$MyCONNECTION->query($MyQUERY)) echo '!!!'; } 
echo <<<_END 
<FORM action = "222.php" method = "POST"> 
Shift Date <INPUT TYPE = "date" name = "MyDAT"> 
<input type = "submit" value = "ADD SHIFT"> 
function get_post($MyCONNECTION, $var) 
return $MyCONNECTION->real_escape_string($_POST[$var]); 
Here is my display after I added date:

When I want to see the new data in my table I get this:

I wonder if anyone could explain why the new date was not added to my table. I did try to reverse it (dd-mm-yyyy->yyyy-mm-dd) but that didn't work either.

RE: How do I add a "date" value to MySQL table using PHP?

So what does the query you are running end up looking like once the values are substituted?

Do you get any errors after running the insert statement? You should be since you are not quoting your date string.

The MYSQL online manual has this to say about date fields:

DD-MM-YYYY is not a valid date format for MYSQL. YYYY-MM-DD should work.


$MyQUERY = "INSERT INTO hourShifts(shiftdate) VALUES('$yosDAT')";

Phil AKA Vacunita
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech

RE: How do I add a "date" value to MySQL table using PHP?

Simple as it was, it solved my problem ! Thanks a lot !

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close