0

I want to insert multiple data using add button and the data of dynamically added button doesn't inserted sometimes get 0 and sometimes just no change...

include 'config.php';

if(isset($_POST['submit1'])) {
    $bill_no = isset($_REQUEST['bill_no']) ? $_REQUEST['bill_no'] : '';
    $bill_date = isset($_REQUEST['bill_date']) ? $_REQUEST['bill_date'] : '';

    $proselect = isset($_REQUEST['proselect']) ? $_REQUEST['proselect'] : '';

    $price = isset($_REQUEST['price']) ? $_REQUEST['price'] : '';

    $addItem = isset($_REQUEST['Add1']) ? $_REQUEST['Add1'] : '';
    $check  = "SELECT bill_no from bill_p where bill_no = '$bill_no'";
    $result = mysqli_query($conn,$check);
    $count1 = mysqli_fetch_array($result);

    if ($count1 > 0) {
        echo '<script text="javascript/text">alert("Bill Exist")</script';
    }
    else
    {
        $count = count($REQUEST['price']);

        for($i = 0; $i <= $count; $i++)
        {
            $bill_no = $REQUEST['bill_no'][$i];
            $bill_date = $REQUEST['bill_date'][$i];
            $proselect = $REQUEST['proselect'][$i];
            $price = $REQUEST['price'][$i];

            $query = "INSERT INTO bill_p(p_id,bill_no,b_date,amount) VALUES ('$proselect','$bill_no','$bill_date','$price')";   

            $exe = mysqli_query($conn, $query);
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Keshu Odedara
  • 21
  • 1
  • 5
  • 1
    It would help if you show the actual error text and try and indicate which line is causing the error. – Nigel Ren Feb 16 '19 at 07:48
  • Notice: Array to string conversion in C:\xampp\htdocs\Bill\admor.php on line 14 $addItem = isset($_REQUEST['Add1']) ? $_REQUEST['Add1'] : ''; $check = "SELECT bill_no from bill_p where bill_no = '$bill_no'"; The Add1 is button name and Id – Keshu Odedara Feb 16 '19 at 07:50
  • Which is line 14? – Nigel Ren Feb 16 '19 at 07:51
  • Your test to check if the row exists may be the problem change `if ($count1>0){` to `if ($count1 !== false){` as `mysqli_fetch_array()` will return false if nothing is found. – Nigel Ren Feb 16 '19 at 07:53
  • As your later code uses `$_REQUEST['bill_no']` as an array, it looks as though you have a list of items. Do you want to check if any exist or if they all exist? – Nigel Ren Feb 16 '19 at 07:57

0 Answers0