Why do I get the MySQL Error “Query was empty”?

前端 未结 3 2151
北荒
北荒 2020-12-20 16:08
$id = $_REQUEST[\'id\'];
$Section = $_REQUEST[\'section\'];
$Subject = $_REQUEST[\'subject\'];
$type = $_REQUEST[\'type\'];
$Start_date1 = isset($_REQUEST[\'startTxt         


        
相关标签:
3条回答
  • 2020-12-20 16:20

    You're calling mysql_query() twice, once with a non-existent $sql parameter:

    mysql_query("UPDATE service SET Start_date='$Date1', Venue='$Venue', Facilitator='$Faci' WHERE ServiceID ='$id'");
    if (!mysql_query($sql,$con))
    

    should be:

    if (!mysql_query("UPDATE service SET Start_date='$Date1', Venue='$Venue', Facilitator='$Faci' WHERE ServiceID ='$id'"))
    

    You're also not escaping your input, leaving you open to SQL injection. You should use bound parameters ideally, or at the very least run your parameters through mysql_real_escape_string().

    For example:

    $Date1 = mysql_real_escape_string($Date1, $conn);
    
    0 讨论(0)
  • 2020-12-20 16:25

    You are not setting the $sql variable and calling mysql_query() twice.

    0 讨论(0)
  • 2020-12-20 16:36

    Please, for the love of the internet, don't built an SQL query yourself. Use PDO.

    0 讨论(0)
提交回复
热议问题