SQL插入查询不适用于JQuery UI Datepicker

伊恩·巴特勒

html输入:

<input name="week_ending" type="text" id="week_ending" value="" />

jQuery:

<script>
    $(function() {
        $( "#week_ending" ).datepicker();
    });
</script>

PHP代码:

$week_ending = db_quote($_POST['week_ending']);

function db_quote($value) {
    $connection = db_connect();
    return "'" . mysqli_real_escape_string($connection,$value) . "'";
}

SQL:

$result = db_query("INSERT INTO `timesheets` (clientid, candid, weekending, department, orderno, basicpay, basiccharge, otpay, otcharge, ot2pay, ot2charge, status, hue, huc) VALUES ($client, $cand, $week_ending, $department, $order_no, $basic_pay, $basic_charge, $ot_pay, $ot_charge, $ot2_pay, $ot2_charge, $status, $hue, $huc)");
    if($result){
        print 'Success! ID of last inserted record is';
    } 
    else {
        die('Error : ' . db_error());
    }

我插入的每一行timesheets的日期都为0000-00-00数据类型datetimesheets表中设置为

选择日期后检查元素时,HTML为:

<input class="hasDatepicker" name="week_ending" id="week_ending" value="" type="text">

我猜这解释了0000-00-00进入数据库的原因。我尝试添加,.formatDate但似乎没有什么不同,尝试更改为,<input type="date">但该value属性中仍然没有任何内容

R

您可以使用PHP函数:date()strtotime的格式解析成时间戳,然后到正确的日期格式。

请注意,用户可能用错误的数据更改输入字段。

$week_ending = db_quote(date('Y-m-d',strtotime($_POST['week_ending'])));

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章