There are few issues with your code, such as:
strtotime()
function returns an integer timestamp, not a DateTime
object, so you can't call format()
method like this way.
$start = strtotime("now");
$start->format('U');
// etc. are wrong
Instead, create a DateTime
object and then call it's format()
method, like this:
$start = new DateTime("now");
$start->format('U');
// etc.
Now comes to your issue,
it's giving a parse error
That's because of your while
condition,
while($start->format('U') > $date->format('U') > $end->format('U')){ ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
May be, you want to do something like this:
while($start->format('U') < $date->format('U') && $date->format('U') > $end->format('U')){
// your code
}
Sidenotes:
There's no point including the connection handler in each iteration of the loop, so take this statement, require_once('connect.php');
outside of your while
loop.
Learn about prepared statements because right now your query is susceptible to SQL injection. Also see how you can prevent SQL injection in PHP.
Edited:
i want to enter a data of only last 7 days from entry time...
If that's your requirement, then you can do this using either strtotime()
function or DateTime
class,
(1) Using strtotime() function
// your code
$content = $_POST['content'];
$start = strtotime("-7 days");
$date = strtotime($date);
$end = strtotime("now");
And there's no point using a while
loop, a simple if
condition will do just fine,
if($start <= $date && $end >= $date){
// your code
}
(2) Using DateTime class
// your code
$content = $_POST['content'];
$start = new DateTime("-7 days");
$date = new DateTime($date);
$end = new DateTime("now");
And there's no point using a while
loop, a simple if
condition will do just fine,
if($start->format('U') <= $date->format('U') && $end->format('U') >= $date->format('U')){
// your code
}