简体   繁体   中英

Php Mysql insert query doesnt work under if condition or direct

Mysql insert query is not insert under condition. 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. read more on this link http://php.net/manual/en/mysqli.quickstart.multiple-statement.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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