简体   繁体   中英

sql update query in php

I am trying to do an update query in php to update my database but the query is not working. It is probably something simple.

$query = "UPDATE Events 
          SET charity_name = '$charity_name' ,
              charity_reg = $charity_reg ,
              Event_Name = '$event_tit', 
              Event_Status_Code = '$event_stat', 
              Start_Date = $event_dat, 
              Hours = $event_hour, 
              location = '$event_loc', 
              Other_Details = $event_content,
              event_image = $imageData, 
              image_name = '$imageName', 
              max_available_spaces = $event_spaces, 
              Event_type = '$eve_category', 
              event_cost = $event_cost, 
              event_organiser = '$event_organiser' 
          WHERE Event_ID = $the_event_id";

You are not putting quotes ('') around some values, that might be a problem unless all thoses values are boolean/ints. Make sure to put quotes around all values, like '$imageData' instead of $imageData Also watch out for sql injections when you are directly inputting the values in your query. Better to use prepared statements

$query = "UPDATE Events 
          SET charity_name = '$charity_name' ,
              charity_reg = '$charity_reg' ,
              Event_Name = '$event_tit', 
              Event_Status_Code = '$event_stat', 
              Start_Date = '$event_dat', 
              Hours = '$event_hour', 
              location = '$event_loc', 
              Other_Details = '$event_content',
              event_image = '$imageData', 
              image_name = '$imageName', 
              max_available_spaces = '$event_spaces', 
              Event_type = '$eve_category', 
              event_cost = '$event_cost', 
              event_organiser = '$event_organiser' 
          WHERE Event_ID = $the_event_id;";

EDIT: as @dWinder mentioned: if $the_event_id is not an integer, make sure to also put quotes around that value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM