0

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>   
4
Contributors
6
Replies
7
Views
4 Years
Discussion Span
Last Post by diafol
0

@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?

Edited by LastMitch: grammer

0

yes, I am using JQuery Datepicker.

I do have date column Tanggal = Date.

0

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.

0

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

}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.