简体   繁体   English

php中的sql更新查询

[英]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. 我正在尝试在php中执行更新查询以更新数据库,但该查询无法正常工作。 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. 确保将所有值都用引号引起来,例如'$imageData'而不是$imageData 。在直接在查询中输入值时也要注意sql注入。 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. 编辑:如@dWinder所述:如果$the_event_id不是整数,请确保也将引号引起来。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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