0

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

}
Fahad Almehaini
  • 233
  • 3
  • 18
  • 1
    ***Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php).*** [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Apr 06 '17 at 21:26
  • Can you do some proper code indentation? It'll make things easier to read and you might see the problem. – Jay Blanchard Apr 06 '17 at 21:27
  • Have you checked your error logs? You're making an assumption the query is working. Add error reporting to the top of your file(s) right after your opening ` – Jay Blanchard Apr 06 '17 at 21:29
  • first you are using mysql, second you are not checking error, third if query does not work, that's simply means there is some thing wrong in the query, check your query – arif_suhail_123 Apr 06 '17 at 21:30
  • its not giving any kind of error – Fahad Almehaini Apr 06 '17 at 21:36

1 Answers1

0

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

nellytadi
  • 91
  • 1
  • 15