mercredi 4 janvier 2017

If statement in sql query not working in wordpress

This is my piece of code and the check_result variable is coming to be 0, when it shouldn't be 0, please help

$check_result = $wpdb->get_var("SELECT COUNT(ID) FROM $table_name3  WHERE IF('$admin_Name' != '', admin_id = '$admin_ID_result', 1=1) AND
                                        IF('$client_Name' != '', client_id = '$client_ID_result', 1=1) AND IF('$date' != '' && '$date2' == '', DATE(time) BETWEEN '$date1' AND '2050-12-31', 1=1)
                                        AND IF('$date2' != '' && '$date' == '', DATE(time) BETWEEN '2000-12-31' AND '$date2', 1=1)
                                        AND IF('$date' != '' && '$date2' != '', DATE(time) BETWEEN '$date1' AND '$date2', 1=1)");

This is the html

echo "<form method='post' action='" . $_SERVER['REQUEST_URI'] . "'>
         Admin Email: <br/><input type='text' name='admin_Name' maxlength='100'>
                      <br/><br/>
         Client Email:<br/><input type='text' name='client_Name' max='100'>
                      <br/><br/>
         Date From:   <input type='date' name='date' min='1990-12-31' max='2050-12-31'>
         Date To:     <input type='date' name='date2' min='1990-12-31' max='2050-12-31'>
                      <br/><br/>
                      <input type='submit' name='Submit'>
      </form>";

Aucun commentaire:

Enregistrer un commentaire