简体   繁体   English

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

[英]Php Mysql insert query doesnt work under if condition or direct

Mysql insert query is not insert under condition. mysql插入查询条件下不插入。 Its not giving any kind of error. 它没有给出任何类型的错误。 But update query is working. 但是更新查询正在工作。 please help 请帮忙

//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)");

}

you need to use mysqli_multi_query() to perform multiple queries. 您需要使用mysqli_multi_query()来执行多个查询。 read more on this link http://php.net/manual/en/mysqli.quickstart.multiple-statement.php 在此链接上了解更多信息http://php.net/manual/en/mysqli.quickstart.multiple-statement.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM