php mysqli 更新查询

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22322364/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 04:50:07  来源:igfitidea点击:

php mysqli update query

php

提问by skampen

I have the following php script to update my db, but it doesn't work. the two echo's show in the ui that the variables are filled with correct values. The query doensn't seem to be executed though. I don't get any errors whatsoever.

我有以下 php 脚本来更新我的数据库,但它不起作用。用户界面中的两个回声显示变量填充了正确的值。查询似乎没有被执行。我没有收到任何错误。

<?
    $rapportId = $_GET['variable1'];
    $rapportNaam = $_GET['variable2'];

    echo "rapportId = ". $rapportId;
    echo "<br>rapportNaam = ".$rapportNaam;     

    $mysqli = new mysqli("localhost", "twrwe", "twrewtww", "trwtw");

  $mysqli->query("Update Rapporten Set RapportNaam = $rapportNaam
                  Where RapportId = $rapportId
        ")or die(mysqli_error($db));
  $mysqli->commit();
    if ($mysqli->error) {
       printf("Errormessage: %s\n", $mysqli->error);
    }
  mysqli_free_result();
?>

回答by Abhik Chakraborty

You need to use '' for string data in query as

您需要使用 '' 作为查询中的字符串数据

$mysqli->query("Update Rapporten 
Set RapportNaam = '$rapportNaam'
Where RapportId = $rapportId
") ;