PHP UPDATE“字段列表”中的未知列“名称”

时间:2018-08-15 21:52:51

标签: php mysql

在使用PHP更新数据库时,我似乎遇到了问题。我不断收到错误消息:

ERROR: Could not able to execute UPDATE settings SET value='0' WHERE id='2'. Unknown column 'value' in 'field list'

但是“值”列确实存在,我尝试了人们在问相同的问题时曾经说过的错误,但到目前为止没有任何效果。造成此失败的原因是什么?

完整代码:         

require 'config.php';

$link = mysqli_connect("LocalHost", "PSRPCADM", "999989Ki9?", "PSRPC");



// Check connection

if($link === false){

    die("ERROR: Could not connect. " . mysqli_connect_error());

}



// Escape user inputs for security
if(isset($_POST['Monday']) &&
$_POST['Monday'] == 'Yes')
{
$monday = "1";
}
else
{
$monday = "0";
}   



// attempt insert query execution


$sql = "UPDATE settings SET value='$monday' WHERE id='2'";




if(mysqli_query($link, $sql)){

echo "it worked";


} else{

    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);

}



// close connection

// close connection

mysqli_close($link);

3 个答案:

答案 0 :(得分:2)

value是mysql中的关键字,您可以尝试在value之间使用引号字符

"UPDATE settings SET `value`='$monday' WHERE id='2'"

here

答案 1 :(得分:1)

尝试一下

public partial class TheGridView : Window
{
    TheGridViewModel _viewModel;
    public ICommand SetService; 

    [ImportingConstructor]
    public TheGridView(TheGridViewModel vm)
    {
        DataContext = _viewModel = vm;
        vm.RefreshListItems += () => TheGrid.Items.Refresh();

        InitializeComponent();
        Closing += Window_Closing;

        SetService = new RelayCommand(SetSvc);
    }

    private void SetSvc(object selectedItem)
    {
        // Doesn't get here
    }
}

希望获得帮助

答案 2 :(得分:0)

$sql = "UPDATE settings SET value='$monday' WHERE id='2'";

在此行中,您输入的是字符串'$ monday',而不是$ monday的内容。可能引发了错误,因为数据库中的“值”不支持字符串。找不到其他错误。