在PHP中发布数据值时出错

时间:2010-12-09 07:03:38

标签: php mysql

每当我尝试在PHP中发布数据值时,我都会收到以下错误:

  

致命错误:未捕获的异常   信息'异常'   'dateTime :: __ construct()[datetime .-- construct]:无法解析时间字符串(这个   星期三G:我A)在位置16(:):   意外的角色'in   C:\ XAMPP \ htdocs中\键盘\ end.php:14   堆栈跟踪:#0   C:\ XAMPP \ htdocs中\键盘\ end.php(14):   DateTime-> __ construct('本周三   ......')#1 {main}投入   在线C:\ xampp \ htdocs \ keypad \ end.php   14

以下是我正在使用的代码:

<?php require_once('Connections/rent.php'); ?>
<?php

// post

$id = $_GET['id'];
$user = $_GET['user'];
$week = $_GET['week'];
$pRent = $_GET['pRent'];
$status = $_GET['status'];
$rentPaid = $_GET['rentPaid'];
$result = $_GET['result'];
$pDate = date("d/m/Y G:i A");
$lDate = new DateTime('this wednesday G:i A');
$cDate = new DateTime('next tuesday G:i A');

// update 

mysql_query("UPDATE rent SET dNo = '$dNo', pdate = '$pDate', pRent = '$result' WHERE rent.id = $id");


// if pRent = 0 then set status to clear, colour to #3C0
if ($pRent == 0 ) {
    mysql_query("UPDATE rent SET status = 'clear', colour = '#3C0' WHERE rent.id = $id");
} 

// if pRent =! 0 but just paid then set status to paid/not clear, colour to #FF0
elseif ($pRent =! 0 ) {
    mysql_query("UPDATE rent SET status = 'paid', colour = '#3C0' WHERE rent.id = $id");
}

// if status = on holiday, then set status to clear, colour to #3C0
elseif ($status == 'awaiting' ) {
    mysql_query("UPDATE rent SET status = 'awaiting', colour = '#09F' WHERE rent.id = $id");
} 

// check all drivers who have/have not paid rent in the past week
elseif ($lDate < $pDate && $cDate > $pDate) {
    //  date is within desired range
    mysql_query("UPDATE rent SET status = 'paid', colour = '#3C0'");
} else {
    // date is not within desired range
    mysql_query("UPDATE rent SET status = 'awaiting', colour = '#09F' WHERE rent.status =! 'not working'");
}
?>

有什么建议吗?

1 个答案:

答案 0 :(得分:3)

第14行遇到问题,$lDate = new DateTime('this wednesday G:i A')无效,请查看Relative DateTime formats以获取有效列表。你需要做的是:

 $lDate = new DateTime('this wednesday')
 $lDate->format('G:i A');

只是一个建议,前两行应该是

 <?php 
     require_once 'Connections/rent.php';

请考虑使用PDO或其他类似的库,或者至少清理SQL查询。