来自 php 的 Mysql 查询更新


Mysql Query Update From php

大家好,我在 PHP 中查询更新记录时遇到了问题。

 <?php
include('../webcgo/script/cox.php');
$query = $cox->query("SELECT cf_id FROM offerte;");
while ($idx = mysqli_fetch_array($query)) {
    $check = '<button class="uk-button" onclick="location.href=''http://localhost/chartscript/remRegola.php?dis=2&id=' . $idx['cf_id'] . '''">OK</button>';
    $query_check = 'UPDATE offerte SET check=''' . $check . ''' WHERE cf_id=' . $idx['cf_id'].';';
    if ($queryx = $cox->query($query_check) === TRUE) {
        echo "Record updated successfully";
    } else {
        echo "Error updating record: " . $cox->error;
    }
}
mysqli_close($cox);?>

结果:更新记录时出错:SQL 语法有误;检查与您的MySQL服务器版本相对应的手册,了解在"check="附近使用的正确语法

check是一个MySQL保留关键字。如果要在查询中使用它,则必须将其包装在反引号中:

 $query_check = 'UPDATE agoragroup_chronoforms_data_inserimento_offerte_prod SET `check`=''' . $check . ''' WHERE cf_id=' . $idx['cf_id'].';';