Datepicker日期格式insert和0000-00-00

时间:2015-03-11 10:28:57

标签: php mysql insert date-format

我搜索了上述主题并找到了各种答案,但没有帮助我 每当我从ny web表单发布日期时,我桌子上的结果总是有效的 我已经在这2天了,并尝试了我找到的所有建议但无济于事。我相信我错过了一个非常小的细节。这是我的代码:

<html>

<head>
<meta charset="utf-8">
<title>IBADAM BMs</title>

<link rel="stylesheet" href="//code.jquery.com/ui/1.11.3/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.3/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">


<script>
$(function() {
$("#datepicker").datepicker({dateFormat: 'yy-mm-dd'});
});
</script>


</head>

<body bgcolor="#E6E6FA">

<br>
<div>
    <div style="float: left; margin-left: 340px;>
    <a href="index2.php"><img src="../image/banner.png" alt="" align=""/></a>
</div>

<br><br><br><br><br>

<div style="float: left; margin-left: 1100px; margin-top: 0px;">
<a href="../logout.php">Log out</a>
</div>
<br><br>
<center><b><h3>DIVISION</h3></b></center>

<?php
error_reporting (E_ALL ^ (E_NOTICE + E_WARNING));
$con=mysqli_connect("localhost","alagbeco","a12345","alagbeco_modem");
// Check connection
if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}


if(!isset($_POST['submit'])) {
    ?>

<center>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<br><br>


Branch: 
<select name="branch">
<option></option>
<option>DIVINE</option>
<option>GLORY 1</option>
<option>GLORY 2</option>
</select>

<br><br>

Date: 
<input type="text"  name="datepicker" id="datepicker">
<br><br>


Amount: 
<input type="text" name="amount">
<br><br>

<input type="submit" name = "submit" value ="Process">
</form>
</center>


    <?php



} else {
        // escape variables for security
        $branch = $_POST['branch'];
        $amount = $_POST['amount'];
        $datepicker = $_POST['date'];

        //check for existence
        $check_sql = "SELECT count(no) FROM bm_ibadan_division WHERE branch= '$branch' AND date = '$datepicker'";
        $check = mysqli_query($con,$check_sql);
        while ($check_rsult = mysqli_fetch_array($check)) {
            $count = $check_rsult['count(no)'];
            if($count >0 ) {
                die ("Double treatment not allowed");
            } else {



                    //insert into table
                    $sql = "INSERT INTO bm_ibadan_division (branch, status, amount, date)
                    VALUES ('$branch', 'Reconciled', '$amount', '$datepicker')";
                    $result = mysqli_query($con, $sql);
                }       echo '<br><br><center>Entry Successful</center><br><br>';   
        }   
}

?> 

<br>
</body>
</html>

5 个答案:

答案 0 :(得分:2)

Formate应该是yy-mm-dd。试试这样:

<script>
$(function() {
$("#datepicker").datepicker({dateFormat: 'yy-mm-dd'});
 });
</script>

也改变: $ datepicker = $ _POST [&#39; date&#39;];到$ datepicker = $ _POST [&#39; datepicker&#39;];

答案 1 :(得分:0)

日期格式必须为YYYY-MM-DD

<script>
$(function() {
$("#datepicker").datepicker({dateFormat: 'yyyy-mm-dd'});
});
</script>

答案 2 :(得分:0)

要么改变这个

<input type="text"  name="datepicker" id="datepicker">

<input type="text"  name="date" id="datepicker">

更改

$_POST['date']

$_POST['datepicker']

答案 3 :(得分:0)

php代码中

$datepicker=$_POST['date']喜欢这样。

请更改为$_POST['datepicker']。然后它会工作。谢谢

答案 4 :(得分:0)

我也遇到了这个问题,我使用了以下代码:

date('Y-m-d', strtotime(str_replace('/', '-', $_POST['date'])))