1

I need to read the 'month' from table site_salmonusage. Here is the example of data in site_salmonusage. Then i need to count whether the data is exist or not, If it exist, then i need to update all data in that 'month'. If not exist, it will insert into.

if ($_POST['register']){
$entry_id=$_POST["entry_id"];
$storenum = $_POST["storenum"];
$store_name=$_POST["store_name"];
$month = $_POST["month"];
$usage = $_POST["usage"];

$remove=mysqli_query($con,"SELECT COUNT(*)  As count FROM site_salmonusage WHERE month='$month' AND storenum='$storenum'");

$row=mysqli_fetch_array($remove);

if($row['count']==1){

    $add1 = "UPDATE site_salmonusage
SET  usage='$usage'
WHERE storenum='$storenum' AND month='$month'";
} 

else if($row['count']==0){
$add = "INSERT INTO site_salmonusage (storenum, month, usage)
VALUES ('$storenum','$month',$usage')";
}
else {
    $del= "DELETE  FROM site_salmonusage WHERE month='$month'"; 
    $adding="INSERT INTO site_salmonusage (storenum,month,usage)
    VALUES ('$storenum','$month','$usage')";
}

Here is my php. But after submit button, it not insert into database.

Felix
  • 571
  • 14
  • 34
Azim Azman
  • 97
  • 1
  • 1
  • 9

0 Answers0