There are three fields in this forms:

1.Produk
2.Jumlah
3.Tanggal

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

<html>

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>jQuery UI Datepicker - Default functionality</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.0/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script src="http://code.jquery.com/ui/1.10.0/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
</head>
</html>






<h4>STOCK RECORDING SYSTEM</h4>


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

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

            $username='root';
            $password='';

            $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>
            <?php            
            }

            ?>
        </select>
        </td>    
    </tr>    
    <tr>
        <td>Jumlah  :</td>
        <td><input type="text" size="12" maxlength="22" name="Jumlah" value="2 box 1 pack"></td><br> 
    <tr>
        <?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>
    </tr>    
    <?php
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\";
    </script>";
}
    ?>
    </table>

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

</form>   

Recommended Answers

All 6 Replies

Member Avatar for LastMitch

@davy_yg

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 for LastMitch

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");
    exit();

}
Member Avatar for diafol

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, networking, learning, and sharing knowledge.