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)");
}
最佳答案
您需要使用mysqli_multi_query()来执行多个查询。在此链接上了解更多信息 http://php.net/manual/en/mysqli.quickstart.multiple-statement.php
关于Php Mysql插入查询在if条件或直接条件下不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43266029/