0

I am using fullcalendar, I have a checkbox on the home page which decides which events are shown.

One of the options are all of the events, and the other option are specifically tailored events.

$alterAMPM = $_POST['alterAMPM'];
$AMPM = $_POST['ampm'];
$alterDate = $_POST['alterDate'];
$date = $_POST['date'];
$dateTime = $_POST['datetime'];
$alterDoctor = $_POST['alterDoctor'];
$doctor = $_POST['doctor'];


$json = array();

// Query that retrieves events
$buildQuery = "SELECT * FROM DoctorAvailability WHERE backgroundColor = 'green'";

if ($alterAMPM = 'No'){
    if ($AMPM = 'A'){
        $buildQuery .= " AND start < $date";
    }else if($AMPM = 'P'){
        $buildQuery .= " AND start > $date";
    }
}
if ($alterDate = 'No'){
    $buildQuery .= " AND start >= $date AND start < DATE_ADD($date, INTERVAL 1 DAY)";
}

if ($alterDoctor = 'No'){
    $buildQuery .= " AND title = $doctor";
}

I am building the query depending on data brought back.

The correct string is passed HTML side.

http://localhost:8080/php/getrecommendedappoint.php?alterAMPM=Yes&ampm=A&alterDate=No&date=2015-12-04&datetime=2015-12-04%2012:00:00&alterDoctor=Yes&doctor=Curly&start=2015-12-07&end=2015-12-14&_=1449492506627

but when printing out the string sent the following is shown.

SELECT * FROM DoctorAvailability WHERE backgroundColor = 'green' AND start < AND start >= AND start < DATE_ADD(, INTERVAL 1 DAY) AND title =

For some reason the values aren't being added in..

I have tried by using " + valuetoadd + " as well.

Within other queries the way I have used has worked fine.

@Saty answered this question correctly. I needed to replace POST with GET. I don't believe this is a duplicate.

bananabreadbob
  • 369
  • 2
  • 10
  • 26
  • is `$doctor` a string? looks like it `&doctor=Curly`. Having checked for errors would have told you about that, and need to be quoted. `AND title = '$doctor'";` – Funk Forty Niner Dec 07 '15 at 13:00
  • Post the value of `print_r($_POST);` – Saty Dec 07 '15 at 13:01
  • @Fred-ii- It is the variable declared from the GET at the top of the php. Previously i have included the values I wanted to use for the query like that. I have also tried the `"title =" + $doctor` – bananabreadbob Dec 07 '15 at 13:02
  • As per your url you have to use `$_GET` – Saty Dec 07 '15 at 13:03
  • @Saty what do you mean? Also do I put the print_r($_POST); within the php code? – bananabreadbob Dec 07 '15 at 13:05
  • `Array ( ) Array ( [0] => 42000 [1] => 1064 [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND start >= AND start < DATE_ADD(, INTERVAL 1 DAY) AND title =' at line 1 ) 1` @Saty that is shown – bananabreadbob Dec 07 '15 at 13:06
  • Now post value of `print_r($_GET)`. As you see your array is empty while using post method – Saty Dec 07 '15 at 13:07
  • `Array ( [alterAMPM] => Yes [ampm] => A [alterDate] => No [date] => 2015-12-04 [datetime] => 2015-12-04 12:00:00 [alterDoctor] => Yes [doctor] => Curly [start] => 2015-12-07 [end] => 2015-12-14 [_] => 1449492924868 ) Array ( [0] => 42000 [1] => 1064 [2] => ` @Saty – bananabreadbob Dec 07 '15 at 13:13
  • So change `$_POST` to `$_GET` in your code – Saty Dec 07 '15 at 13:15
  • Great that worked. The fact that this has been marked as a duplicate didn't answer the question. Your response did. Thank you. @Saty – bananabreadbob Dec 07 '15 at 13:18
  • @barryspikebob happy to help you!! enjoy – Saty Dec 07 '15 at 13:19

0 Answers0