Php Mysql插入查询在条件或直接下不起作用

时间:2017-04-06 21:25:42

标签: php mysql

Mysql插入查询不在条件下插入。它没有给出任何错误。但更新查询正在运行。请帮忙

//this query gets the status of reward system if its enabled
$reward =   mysql_fetch_assoc(mysql_query("
            select * from on_off where ename = 'reward' and status = 1
            "));
            $trueN  =   $reward['status'];

//this query gets the info if member already exist
// if member record already exist then it will update otherwise it will insert
$rewardz    =   mysql_query("
            select * from rewards where mem_id = 1
            ");
            $trueM  =   mysql_num_rows($rewardz);

if ($trueN == 1 && $trueM == 1){

mysql_query("
update rewards
set amount = 12
where mem_id = 1
");

}elseif ($trueN == 1 && $trueM == 0){

$insert=mysql_query("INSERT INTO `rewards` (`amount`, `mem_id`)
VALUES (1, 1)");

}

1 个答案:

答案 0 :(得分:0)

您需要使用mysqli_multi_query()来执行多个查询。详细了解此链接http://php.net/manual/en/mysqli.quickstart.multiple-statement.php