Getting date with jQuery and saving it to MySQL with a PHP form

I need a small example on sending date to mysql db from a php form. Tried lots of examples but I seems I am missing o step. I have prepared a form for 3 fields, name last name and birth date. When I fill the form and submit date filed gets crazy :) 0000-00-00 00:00:00

I tried to format the date but this time I could not understand how to pass it to mysql. Here is my funny code;

<?php include "header.php" ?>
<?php include "conn.php" ?>
    $(function() {
        $( "#bdate" ).datepicker();
        $PlayerName = $_POST['PlayerName'];
        $PlayerLname = $_POST['PlayerLname'];
        $PlayerBdate = $_POST['PlayerBdate'];
        $query = "INSERT INTO tblPlayer (
                PlayerName, PlayerLname, PlayerBdate
    ) VALUES (
        '{$PlayerName}', '{$PlayerLname}', '{$PlayerBdate}'
            header("Location: players_list.php");
        } else{
            echo "<p>something is wrong</p>";
            echo "<p>" . mysql_error() . "</p>";

<form action="add_player.php" method="post">
   <td>Name: </td>
   <td><input type="text" name="PlayerName" /></td>
   <td><input type="text" name="PlayerLastName" /></td>
   <td><input id="bdate" type="text" name="PlayerBdate" /></td>
   <td><input type="submit" name="submit" value="Save" /></td>
   <td align="right">&nbsp;</td>
<?php ob_end_flush() ?>
<?php include ("footer.php") ?>

header.php contains

<?php ob_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="" />
    <script src=""></script>
    <script src=""></script>
<title>Untitled Document</title>

and conn.php is the standard connection sting file.Footer.php is just closing the connection:) Also I could not make my code work without the ob_start(); and end functions:S

So can you point out how can I get the date as day/month/year format and save it to mysql that way?


since your date in mysql is in Y-m-d H:i:s format.. use php date() function to convert the date into required format.


$PlayerBdate = $_POST['PlayerBdate'];


 $PlayerBdate = date('Y-m-d H:i:s',strtotime($_POST['PlayerBdate']));

Need Your Help

Sequelize OR with null

sql node.js sequelize.js

I am trying to use Sequelize to generate a (semi) complex conditional.

JavaScript - How escape quotes in a var to pass data through Json

javascript json

I'm passing some data through Json to a Webservice.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.