PHP 将函数分解为 MYSQL 数据库

PHP explode function into MYSQL database

我如何让它工作? 尝试使用 explode 函数并插入我的数据库 table,但值没有发送到我的数据库 table。

HTML:

<select id="customer_name" name="customer_name" required>
    <option value="">Select customer...</option>
    <?php
    $sqli = "SELECT * FROM customer order by customer_name";
    $result = mysqli_query($conn, $sqli);
    while ($row = mysqli_fetch_array($result)) {
    echo '<option>'.$row['customer_name'].'|'.$row['customer_ID'].'</option>';
    }
    ?>
    </select>

PHP:

<?php
include_once 'database.php';

$stmt1 = $conn->prepare("INSERT INTO persons(person_ID, customer_name, customer_ID) VALUES (?,?,?)");

$result = $_POST['customer_name'];
$result_explode = explode('|', $result);

$person_ID = $_REQUEST['person_ID'];
$customer_name= $_REQUEST['$result_explode[0]'];
$customer_ID= $_REQUEST['$result_explode[1]'];

$stmt1->bind_param("sss", $person_ID, $customer_name, $customer_ID);

$stmt1->execute();

echo "<strong>Record saved....</strong>"; echo 'returning to add another person. If no more persons to add please close this window.';

mysqli_close($conn);
?>

以上returns错误: 未定义索引:$result_explode[0] 未定义索引:$result_explode[1] 但是我不确定如何定义这些(我在阶梯曲线上自学)

参考这里解决:https://www.stechies.com/undefined-index-error-php/

While working in PHP, you will come across two methods called $_POST and $_GET. These methods are used for obtaining values from the user through a form. When using them, you might encounter an error called “Notice: Undefined Index”.

This error means that within your code, there is a variable or constant that has no value assigned to it. But you may be trying to use the values obtained through the user form in your PHP code.

The error can be avoided by using the isset() function. This function will check whether the index variables are assigned a value or not, before using them.