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

标签 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)");

}

最佳答案

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

关于Php Mysql插入查询在if条件或直接条件下不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43266029/

相关文章:

javascript - 如何构造javascript数组

php - 为什么主键值上的 is_int 返回字符串?

sql - rails 3 : Can't create relationship :has_one

mysql - 在另一个查询中使用表别名来遍历树

python - MySQL 和 Python : How to map the table data?

php - foreach 循环内的表单无法正常工作

javascript - AJAX - 发布表行和单独输入

PHP - 插入值错误 : Check SQL version

php - 存储 HABTM 协会中持有的项目的排序顺序 - CakePHP

javascript - 如何使用ajax插入mysql表?