Why does this SQL UPDATE query not work with a variable for WHERE?

后端 未结 4 1973
悲&欢浪女
悲&欢浪女 2020-12-20 09:40

this is my first post here at Stack Overflow. I know the question has been asked many times before. I went through many answers, tried all of them (except the correct approa

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-20 10:27

    Column Names are not givn in query

    UPDATE table_name SET column_name1 = expr1, column_name2 = expr2, ... [WHERE condition];

    So, your query will be something like this and check column names in database:

    $sql =  "UPDATE VideoArchiv             
                    SET titel='".$_POST["titel"]."',schauspieler='".$_POST["schauspieler"]."'
                    WHERE id=$id";
    

    Note: This is sql vulnerable, so please add mysql real escape function (https://www.php.net/manual/en/function.mysql-real-escape-string.php) or convert it to pdo.

提交回复
热议问题