-3

I want to separate database into two if i insert more than 1 value.In this picture, you can see 111111 and 111112 are inserted with "," in the same role. I want to make 111111 and 111112 as each line. In picture, you can see 111111 and 111112 are inserted with "," in the same role. I want to make 111111 and 111112 as each line. How can I make this? Below is my db.

    $seal_area = isset ($_GET['site'])? $_GET['site']:'';
$seal_qty = isset ($_GET['seal_qty'])? $_GET['seal_qty']:'';
$receive_by = isset ($_GET['stat'])? $_GET['stat']:'';
$seal_barcode = isset ($_GET['barcodeno'])? $_GET['barcodeno']:'';
$receive_id = isset ($_GET['secuid'])? $_GET['secuid']:'';
//$returnid = isset ($_GET['secuid'])? $_GET['secuid']:'';
$chk = isset ($_GET['chk'])? $_GET['chk']:'';
$admin_name = $_SESSION["loginname"];
if ($chk=='issue'){
    $sql1 = "INSERT INTO access_request.tbl_sealcable (seal_barcode, seal_area, dt_issue, issue_admin, receive_by, receive_id) VALUES ('$seal_barcode','$seal_area',now(),'$admin_name','$receive_by','$receive_id')";
    $result1 = mysqli_query($conn,$sql1);
}
/*else if ($chk=='rtn'){
    $sql1 = "INSERT INTO access_request.tbl_sealcable (seal_barcode, seal_area, dt_issue, return_admin, return_id) VALUES ('$seal_barcode','$seal_area',now(),'$admin_name','$returnid')";
    $result1 = mysqli_query($conn,$sql1);
}*/

flush();
mysqli_close($conn);

below is javascript.

    var barcodeno = document.translot.barcodeno.value;
      if (barcodeno == ""){
          alert("Please Insert Serial Numbers.")
          return false;
      }
      
  

  $('#filter').html(''); // to clear selection
  // lotid = $('#lotid').val().split('\n');
  var barcodeno = $('#barcodeno').val().trim();
  barcodeno = barcodeno.split('\n');
//checking duplicate barcodeno
    let barcodeno_array = []
    for(let i = 0;i < barcodeno.length; i++){
        if(barcodeno_array.indexOf(barcodeno[i]) == -1){
            barcodeno_array.push(barcodeno[i])
        }
    }
Dharman
  • 26,923
  • 21
  • 73
  • 125
scott
  • 60
  • 7
  • 1
    **Warning:** You are wide open to [SQL Injections](https://php.net/manual/en/security.database.sql-injection.php) and should use parameterized **prepared statements** instead of manually building your queries. They are provided by [PDO](https://php.net/manual/pdo.prepared-statements.php) or by [MySQLi](https://php.net/manual/mysqli.quickstart.prepared-statements.php). Never trust any kind of input! Even when your queries are executed only by trusted users, [you are still in risk of corrupting your data](http://bobby-tables.com/). [Escaping is not enough!](https://stackoverflow.com/q/32391315) – Dharman May 11 '22 at 08:26

1 Answers1

0

You can use PHP explode() function, this is used to string to array convert with comma separate after you loop your array in insert query.

if ($chk=='issue'){
 $barcodeArray = explode(",",$seal_barcode));
 foreach($barcodeArray as $value){
   $seal_barcode = $value;
   $sql1 = "INSERT INTO access_request.tbl_sealcable (seal_barcode, seal_area, dt_issue, issue_admin, receive_by, receive_id) VALUES ('$seal_barcode','$seal_area',now(),'$admin_name','$receive_by','$receive_id')";
     $result1 = mysqli_query($conn,$sql1);
 }   
}