簡體   English   中英

PHP Mysql插入查詢在條件或直接下不起作用

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM