Kevin Heimlich Kevin Heimlich - 3 months ago 9
MySQL Question

mysql SET value as variable not working

Following mysqli query not working. I need to assign SET variable value to blink ' ' space or null. But problem is after SET if i use any variable then it not working. Please tell me whats wrong i am doing with this query?

$q = mysqli_query($conn, "UPDATE photo_gallery
SET $name_of_image_to_del=' '
WHERE id='$row_id'");

Answer

First check the value is present and after that you pass in t that query:-

if (isset($name_of_image_to_del) && $name_of_image_to_del != '') {
    $q = mysqli_query($conn, "UPDATE photo_gallery SET $name_of_image_to_del=' ' WHERE id='$row_id'");
}