0

iso.obj.php

$from = null;
$too = null;

if (isset($_POST['search'])) {
    if ($from = null) {
        $from = date("Y-m-d");
    } else {
        $from = $_POST['FromDateTime'];
    }

    if ($too = null) {
        $too = date('Y-m-d', strtotime("+30 days")) . " 23:59:59"; 
    } else {
        $too = $_POST['ToDateTime']." 23:59:59";
    }
}
$sql ="//statement here with
WHERE capDateTime >='{$from}' AND capDateTime <='{$too}'";

The code is working fine but i got problem when person request the page and its return an empty table. But if i select date and time manualy its will display according to the date and time.

My question is: How do i put current date if not set and if set follow the $_POST?

5
  • if($from = null){ ??? and if ($too = null) { you are assigning the values not comparing Commented Oct 7, 2016 at 8:00
  • if ($from === null) { and if ($too === null) { Commented Oct 7, 2016 at 8:02
  • if ($too = null) this ---> = is an assignment operator. If you want to compare it use == comparison operator. See here. Commented Oct 7, 2016 at 8:03
  • Sidenote: By directly using variables in your $sql, you're exposing yourself to SQL injection. Please use PDO or Mysqli see owasp.org/index.php/SQL_Injection Commented Oct 7, 2016 at 8:03
  • @MaartenSchermer thanks for the reminder. Commented Oct 7, 2016 at 8:24

1 Answer 1

2
$from = date("Y-m-d");
$too = date('Y-m-d', strtotime("+30 days")) . " 23:59:59";

if (isset($_POST['search'])) {
    if (!empty($_POST['FromDateTime'])) {
        $from = $_POST['FromDateTime'];
    }

    if (!empty($_POST['ToDateTime'])) {
        $from = $_POST['ToDateTime']." 23:59:59";
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.