php和mysql查询无法得到任何结果

时间:2016-02-29 16:56:21

标签: php mysql mysqli

为什么这段代码不起作用?我确定所有变量都是真的,我查了一下,只是查询问题。

    if ($te['gold']>=$cost_of_production_gold && $te['woods']>=$cost_of_production_woods && $te['metal']>=$cost_of_production_metal) {
    $addpro =   "UPDATE stats SET '" .$resource . "' . _production=" . $nowproduction+2 . " WHERE id=" . $id_of_the_user;
    mysqli_query($connection2,$addpro);
    mysqli_query($connection2, "UPDATE stats SET" . "gold=" . ($te['gold']-$cost_of_production_gold) . " WHERE id=" . $id_of_the_user . ";");
    mysqli_query($connection2, "UPDATE stats SET" . "woods=" . ($te['woods']-$cost_of_production_woods) . " WHERE id=" . $id_of_the_user . ";");
    mysqli_query($connection2, "UPDATE stats SET" . "metal=" . ($te['metal']-$cost_of_production_metal) . " WHERE id=" . $id_of_the_user . ";" );

1 个答案:

答案 0 :(得分:1)

最好只创建一个更新查询,因为您一次只处理一个用户:

if ($te['gold']>=$cost_of_production_gold && $te['woods']>=$cost_of_production_woods && $te['metal']>=$cost_of_production_metal) {

    $addpro = "UPDATE stats SET " . $resource . "_production='" . ($nowproduction+2) . "', gold='" . ($te['gold']-$cost_of_production_gold) . "', woods='" . ($te['woods']-$cost_of_production_woods) . "', metal='" . ($te['metal']-$cost_of_production_metal) . "' WHERE id='" . $id_of_the_user . "' ";
}

另外your script is at risk for SQL Injection Attacks.了解preparedMySQLi语句。