There are three fields in this forms:


I wonder why Tanggal (date) are all 0000-00-00


<!doctype html>
<html lang="en">
<meta charset="utf-8" />
<title>jQuery UI Datepicker - Default functionality</title>
<link rel="stylesheet" href="" />
<script src=""></script>
<script src=""></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
$(function() {
$( "#datepicker" ).datepicker();


<form action="print.php" method="post">
<form enctype="multipart/form-data" method="post" name="form1" target="_self">

<table border="0" width="300">
        <td>Produk  :</td><br>
        <td><!--  onchange="submit();" -->
          <select name="batch">
            <option value="-1" >-- Select Address --</option>


            $con = mysql_connect('localhost', $username, $password);
            mysql_select_db('snack', $con);

            $result = mysql_query("SELECT * FROM PO");

            while($row = mysql_fetch_array($result))
            <option value="<?php echo $row['PO'];?>">
            <?php echo $row['PO'];?></option>

        <td>Jumlah  :</td>
        <td><input type="text" size="12" maxlength="22" name="Jumlah" value="2 box 1 pack"></td><br> 
        <?php // use date picker to automate date ?>
        <td>Tanggal :</td>
        <td><input type="date" id="datepicker" size="12" maxlength="22" name="Tanggal" value=""></td><br>
if (isset($_POST['submit'])){
    mysql_query("INSERT INTO Stock (Produk,Jumlah,Tanggal) VALUES ('$_POST[batch]','$_POST[Jumlah]','$_POST[Tanggal]')");
    echo "<script type=\"text/javascript\">
    window.location = \"print.php\";

    <input name="submit" type="submit" value="Submit">


Recommended Answers

All 6 Replies

Member Avatar


I wonder why Tanggal (date) are all 0000-00-00

Do you have a date column in your db? I don't see any issue with your query. But I am curious to see what you have in your table that displayed:

Tanggal (date): 0000-00-00

Unless you used JQuery Datepicker?

yes, I am using JQuery Datepicker.

I do have date column Tanggal = Date.

Member Avatar

yes, I am using JQuery Datepicker.

Where is your code? Line 13 to line 15??

I do have date column Tanggal = Date.

There's something wrong with your INSERT statement that is prevent the data appearing in your database.

So that's the only query you provided, I think you need fixed your query.

how to fix the query?

It depends on the format of your date that is being posted (echo out the posted date and check). If it is in any other format other than yyyy-mm-dd then the database won't recognise it and will leave as 0000-00-00.

If it is in a different format then you need to amend the format before saving it to the database

if (isset($_POST['submit'])){

    $date = date('Y-m-d', strtotime($_POST['Tanggal']));

    mysql_query("INSERT INTO Stock (Produk,Jumlah,Tanggal) VALUES ('$_POST[batch]','$_POST[Jumlah]','$date')");

    // Also change your javascript redirect to php:
    header("location: print.php");

Member Avatar

You need to clean your post variables.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.