猿问

日期未在数据库中保存正确的值

我今天得到当前日期和年份的年份和月份,并在我的文本框中显示正确的值。但是,当我开始将其提交到数据库时,该值默认变为 2014,而不是文本框的值。似乎是什么问题?


function YearMonth() {

  var d = new Date();

  var n = d.getFullYear();

  var t = d.getUTCMonth()+1;

  var x = n + "-" + t ;

  

  document.getElementById("num").value = x;

}

 <td><input type="text" id="num" name="num"></td></tr>

 

<input type= "button" name= "button_go" onclick="YearMonth()" id= "button_go" value= "GO" /> 

<input type= "submit" name= "submit" id= "submit_form" value= "Submit" />

<?php

    $servername = "localhost";

    $username = "root";

    $password = "";

    $dbname = "_db";

        $connection = new mysqli($servername, $username, $password, $dbname);


            if ($connection->connect_error) {

                die("Connection failed: " . $connection->connect_error);

            }       


$count = $_POST['num'];


       $sql = "INSERT INTO table (no)

            VALUES ($count)";


            if ($connection->query($sql) === TRUE) 

            {


            } 

            else

            {

                echo "Error: " . $sql . "<br>" . $connection->error;

            }


慕姐4208626
浏览 129回答 1
1回答
随时随地看视频慕课网APP
我要回答