MySQL query working in phpmyadmin but not in php code any reason why?
11:16 29 Nov 2018

I am using the following query and would like the results from the query to appear within single quotes such as '10AM'.

$sql2 = mysqli_query($con, "SELECT concat('''', appointment_time ,''''), concat('''', appointment_end_time ,'''') FROM Appointments WHERE appointment_with LIKE 'Sarah'");

if (!$sql2) {
    die('Invalid query: ' . mysqli_error());
}

while ($row2 = mysqli_fetch_assoc($sql2)) {

    $time = array($row2['appointment_time']. "," ." " . $row2['appointment_end_time']);

    $appointment = [];

    foreach ($time as $appointment){
        echo $appointment;
    }

This works fine when I run the code in phpmyadmin but not within my php code as I get the following message.

Notice: Undefined index: appointment_time in /Applications/MAMP/htdocs/booking-system/index.php on line 140

Notice: Undefined index: appointment_end_time in /Applications/MAMP/htdocs/booking-system/index.php on line 140 ,

Why is this happening?

php sql mysql mysqli