Whenever I try to post data values in PHP I get the following error:
Fatal error: Uncaught exception
‘Exception’ with message
‘DateTime::__construct() [datetime.–construct]: Failed to parse time string (this
wednesday G:i A) at position 16 (:):
Unexpected character’ in
C:\xampp\htdocs\keypad\end.php:14
Stack trace: #0
C:\xampp\htdocs\keypad\end.php(14):
DateTime->__construct(‘this wednesday
…’) #1 {main} thrown in
C:\xampp\htdocs\keypad\end.php on line
14
Here is the code I’m using:
<?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'");
}
?>
Any suggestions?
You have a problem on line 14,
$lDate = new DateTime('this wednesday G:i A')is invalid, take a look at Relative DateTime formats for a list of valid ones. What you need to do is:Just a suggestion, first two lines should be
And please consider using PDO or another similar library, or at least sanitize your SQL queries.