jQuery日期选择器无法通过PHP保存在数据库中 [英] Jquery Date picker can't saving in database by php

查看:53
本文介绍了jQuery日期选择器无法通过PHP保存在数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的总代码,但问题是我无法在数据库中插入数据,原因是date-picker.没有date-picker,它将成功插入数据库中,而当总表为空时,则第一次成功插入,而其他时候它不会插入任何东西.请有人帮我吗?

This is my total code but problem is i can't insert data in database reason date-picker .With out date-picker it's insert successfully in database and when total table is empty then it's insert successfully for 1st time but other time it doesn't insert any thing. please any one help me ?

CREATE TABLE IF NOT EXISTS `teacher` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) NOT NULL,
  `father_name` varchar(50) NOT NULL,
  `mother_name` varchar(50) NOT NULL,
  `address` text NOT NULL,
  `sex` varchar(50) NOT NULL,
  `position` varchar(150) NOT NULL,
  `subject` varchar(150) NOT NULL,
  `sallary` int(50) NOT NULL,
  `dtime` date NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `position` (`position`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=69 ;



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

    if (isset($_POST['name'])&&isset($_POST['f_name'])&&isset($_POST['m_name'])&&isset($_POST['dtime'])&&
        isset($_POST['sex'])&&isset($_POST['address'])&&isset($_POST['position'])&&isset($_POST['subject'])
        &&isset($_POST['salary'])) {

        $name = $_POST['name'];
        $father =$_POST['f_name'];
        $mother =$_POST['m_name'];
        $sex =$_POST['sex'];
        $address =  $_POST['address'];
        $position = $_POST['position'];
        $subject    =   $_POST['subject'];
        $salary =   $_POST['salary'];
        $dtime = date('Y-m-d',strtotime($_POST['dtime']));

        if (!$dtime) {
            echo $dtime;
        }else{
            $query = "INSERT INTO teacher (name, father_name, mother_name, address, sex, position, subject, salary,dtime)VALUES('$name','$father','$mother','$address','$sex','$position','$subject','$salary',$dtime)";     
            $query_run = mysqli_query($db,$query);
            if ($query_run) {
                echo 'success!';

            } else {
                echo "try again";
            }
        }
    }
}

HTML:

<hr>
<!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.3/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="style.css">
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
</head>
<form action="teacher_sallary.php" method="POST">
    Name:<br>
    <input type="text" name='name'required><br><br>
    Father Name:<br>
    <input type="text" name='f_name'required><br><br>
    Mother Name :<br>
    <input type="text" name='m_name'required><br><br>
    Address:<br>
    <textarea rows="7" cols="31" name ='address' >
    Please write your address here !
    </textarea> <br><br>
    Sex:<br>
    <select name="sex">
    <option value="male">Male</option>
    <option value="female">Female</option>
    </select><br><br>
    Position:<br>
    <input type="text" name='position' required><br><br>
    Subject:<br>
    <input type="text" name='subject' required><br><br>
    Sallary:<br>
    <input type="text" name='salary' required><br><br>
    Date:<br>
    <br><p><input type="text" id="datepicker" name="dtime"></p><br>
    <input type="hidden" name=  "formsubmitted" value="TRUE" />

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

</form>

</body>
</html>

推荐答案

您需要先正确解析日期,例如对于默认日期格式,请使用%m/%d/%Y.

You need to parse the date correctly first, e.g. for the default date format, use %m/%d/%Y.

这篇关于jQuery日期选择器无法通过PHP保存在数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆