<?php
require_once ("varables.php");

$myJSON['message'] ="خطای اعتبارسنجی";
$myJSON['mmm'] = array();
if(isset($_POST["nekot"]) && isset($_POST["an1d"])
  && isset($_POST["name"])&& isset($_POST["niut"])
  && isset($_POST["chng"]) && isset($_POST["minP"])
  && isset($_POST["extname"]) && isset($_POST["extprice"])
  && isset($_POST["telll"])&& isset($_POST["showprice"])&& isset($_POST["canman"])){
    $canman = 0;
    $name =$_POST["name"];
		$unit =$_POST["niut"];
    $chng =$_POST["chng"];
    $min =$_POST["minP"];
    $exname =$_POST["extname"];
    $exprice =$_POST["extprice"];
    $tell = $_POST["telll"];
    $canman = $_POST["canman"];
    $shp = $_POST["showprice"];
    $connect = @mysqli_connect($hostname,$username,$password,$database);
    if($connect)
    {
        @mysqli_query($connect,"SET CHARACTER SET utf8;");
      $unitQ="SELECT id FROM " . $tbl_company . " LIMIT 1";
      $resQ=@mysqli_query($connect,$unitQ);
      if ($resQ) {
        $u = @mysqli_fetch_assoc($resQ);
          $id= $u["id"];
      }
        $my_query="UPDATE " . $tbl_company . " SET p_unit='".$unit."',showprice='".$shp."',tell='".$tell."',cchprice='".$chng."', name='".$name."', minBuy='".$min."', extname='".$exname."', extprice='".$exprice."', canmanfi='".$canman."' WHERE id = ".$id;
        $result=@mysqli_query($connect,$my_query);
        if (!$result) {
          	$myJSON['message']="خطا هنگام ثبت";
        }
        else
        {
            	$myJSON['message']= "200";
        }
      }
      else{
          $myJSON['message']="خطای اتصال به پایگاه داده";
      }
}
    echo json_encode($myJSON);
?>
