3v4l.org

run code in 300+ PHP versions simultaneously
<?php session_start(); $con = mysqli_connect("localhost", "root", "password", "database_name"); require 'vendor/autoload.php'; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Xlsx; if(isset($_POST['import_file_btn'])) { $allowed_ext = ['xls', 'xlsx']; $fileName = $_FILES['import_file']['name']; $checking = explode(".", $fileName); $file_ext = end($checking); if (in_array($file_ext, $allowed_ext)) { $targetPath = $_FILES['import_file']['tmp_name']; $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($targetPath); $data = $spreadsheet-> getActiveSheet()->toArray(); $data = array_values ($_POST); //NOT WORKING(?) $flippedArray = array_flip($data); //NOT WORKING(?) foreach ($flippedArray as $row) //NOT WORKING(?) { $sku = $row[ $flippedArray['sku'] ]; //Undefined index $p_name = $row[ $flippedArray['p_name'] ]; //Undefined index $id_category = $row[ $flippedArray['id_category'] ]; //Undefined index $id_brand = $row[ $flippedArray['id_brand'] ]; //Undefined index $checkProduct = "SELECT sku FROM ita WHERE sku='$sku'"; $checkProduct_result = mysqli_query ($con, $checkProduct); if (mysqli_num_rows($checkProduct_result) > 0) { $up_query ="UPDATE ita SET p_name='$p_name', id_category='$id_category', id_brand='$id_brand' WHERE sku='$sku' "; $up_result = mysqli_query($con, $up_query); $msg = 1; } else { $in_query = "INSERT INTO ita (sku, p_name, id_category, id_brand) VALUES ('$sku','$p_name', '$idcategory', '$id_brand')"; $in_result = mysqli_query ($con, $in_query); $msg = 1; } } if(isset($msg)) { $_SESSION['status'] = "All data where imported right"; header("Location: index.php"); } else { $_SESSION['status'] = "Error during file import"; header("Location: index.php"); } } else { $_SESSION['status'] = "Invalid file format"; header("Location: index.php"); exit(0); }
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.4, 8.3.6 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in /in/V1LGA:3 Stack trace: #0 {main} thrown in /in/V1LGA on line 3
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in /in/V1LGA:3 Stack trace: #0 {main} thrown in /in/V1LGA on line 3
Process exited with code 255.

preferences:
91.12 ms | 1400 KiB | 4 Q