0

When I choose the expandable radio button and press the save button it should save its data to inventory_status table but the data wont insert into the inventory_status table. I've seen similar questions but still couldn't figure out the cause of the problem.

      <?php 

         if($_POST['save']){


            if ($_POST['supply_type'] == "expandable"){
                $insertI = (mysqli_query($connect, "INSERT INTO inventory_status(stock_prop_no, unit, description, quantity, price) VALUES ('".$sp_num."','".$unit."','".$desc."','".$qty."','".$cost."')"));
        }
            $pr_no      = $_POST['pr_no'];
            $s = mysqli_query($connect,"SELECT purchase_no FROM `sms_request` WHERE purchase_no = '".$pr_no."'");
             if(mysqli_num_rows($s) > 0)
        {
             echo"
                    <script type='text/javascript'>
                    alert('Purchase No. Existed!');
                    window.location.href = 'sms_supply management.php';
                    </script>
                ";
        }

        else{
            $fcluster   = $_POST['fund_cluster'];
            $osection   = $_POST['office_section'];
            $pr_no      = $_POST['pr_no'];
            $rcode      = $_POST['responsibility_code'];
            $desig      = $_POST['desig'];
            $requester  = $_POST['requester'];
            $loc        = $_POST['loc'];
            $purpose    = $_POST['prpose'];
            $ename      = $_POST['entity_name'];
            $date       = $_POST['date'];
            $dateA      = date("Y-m-d",strtotime($date));
            $radioo     = $_POST['supply_type'];


            $ins = mysqli_query($connect, "INSERT INTO sms_purchaserecord(purchase_no, supply_type) VALUES ('".$pr_no."', '".$radioo."')");
            $insS = mysqli_query($connect, "INSERT INTO sms_ris(purchase_no, ris_num) VALUES ('".$pr_no."', '".$pr_no."')");
            $insert = mysqli_query($connect, "INSERT INTO sms_request(purchase_no,sms_request.date, entity_name, fund_cluster, office_section, responsibility_code, purpose, stat) VALUES ('".$pr_no."','".$dateA."','".$ename."', '".$fcluster."', '".$osection."', '".$rcode."','".$purpose."', '1')");
            $inS = mysqli_query($connect, "INSERT INTO sms_iar(iar_num, purchase_no) VALUES ('".$pr_no."', '".$pr_no."')");

            $select = mysqli_query($connect, "SELECT request_IDnum FROM sms_request WHERE purchase_no = '".$pr_no."'");
            while ($row = mysqli_fetch_array($select)){
                $rnum = $row['request_IDnum'];
            }

            $select2 = mysqli_query($connect, "SELECT * FROM sms_branchloc WHERE loc_ID_no = '".$loc."'");
            while ($row1 = mysqli_fetch_array($select2)){
                $loc_num = $row1['loc_ID_no'];
            }

            if ($rnum != NULL AND $loc_num != NULL){
                $insert2 = mysqli_query($connect, "INSERT INTO sms_requester(request_IDnum, name, loc_ID_no, position) VALUES ('".$rnum."', '".$requester."', '".$loc_num."', '".$desig."')");
            }                

        foreach ($_POST['sp_num'] as $row=>$sp_numm) {
          $sp_num = $sp_numm;
          $unit = $_POST['unt'][$row];
          $desc = $_POST['sdesc'][$row];
          $qty = $_POST['sqty'][$row];
          $cost = $_POST['cost'][$row];

          $query = mysqli_query($connect,"INSERT INTO sms_supply (supply_qty,purchase_no,unit_cost,supply_unit,supply_desc,stockproperty_num) VALUES ('".$qty."','".$pr_no."', '".$cost."', '".$unit."','".$desc."', '".$sp_num."')");

        }    
         echo"
                    <script type='text/javascript'>
                    alert('Purchase Request Save.');
                    window.location.href = 'sms_supply management.php';
                    </script>
                ";
            }
    }

This is the table structure of our inventory_status table:enter image description here

  • Try debugging your code and tell us where it gets stuck and if it gets any errors – JensV Mar 20 '19 at 10:57
  • `"INSERT INTO inventory_status(stock_prop_no, unit, description, quantity, price) VALUES ('".$sp_num."','".$unit."','".$desc."','".$qty."','".$cost."')"));` When you are inserting, the variables aren't yet existing. Check php errors – Cid Mar 20 '19 at 11:14
  • All 10 fields in your inventory_status table require non-null value. You only provide 5 values when inserting, it will throw an error. –  Mar 20 '19 at 11:14
  • @JensV there were no errors but the other queries works fine. It's just that one query that doesn't work – Jeric Marquez Mar 20 '19 at 11:14
  • 1
    Possible duplicate of [How do I get PHP errors to display?](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display) – Cid Mar 20 '19 at 11:21

1 Answers1

0

I found one issue on your following query. sms_request.date should be sms_request_date

$insert = mysqli_query($connect, "INSERT INTO sms_request(purchase_no,sms_request.date, entity_name, fund_cluster, office_section, responsibility_code, purpose, stat) VALUES ('".$pr_no."','".$dateA."','".$ename."', '".$fcluster."', '".$osection."', '".$rcode."','".$purpose."', '1')");

Other thing

All these '".$sp_num."','".$unit."','".$desc."','".$qty."','".$cost."')" variables are not defined. so you have to take this condition in loop.

For i.e.

       foreach ($_POST['sp_num'] as $row=>$sp_numm) {
          $sp_num = $sp_numm;
          $unit = $_POST['unt'][$row];
          $desc = $_POST['sdesc'][$row];
          $qty = $_POST['sqty'][$row];
          $cost = $_POST['cost'][$row];

          if ($_POST['supply_type'] == "expandable"){
                $insertI = (mysqli_query($connect, "INSERT INTO inventory_status(stock_prop_no, unit, description, quantity, price) VALUES ('".$sp_num."','".$unit."','".$desc."','".$qty."','".$cost."')"));
        }
          $query = mysqli_query($connect,"INSERT INTO sms_supply (supply_qty,purchase_no,unit_cost,supply_unit,supply_desc,stockproperty_num) VALUES ('".$qty."','".$pr_no."', '".$cost."', '".$unit."','".$desc."', '".$sp_num."')");

        }  
Bhavin Solanki
  • 4,740
  • 3
  • 26
  • 46