How do I get this to work? Trying to use the explode function and insert into my DB table, but the values are not being sent to my DB 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);
?>
The above returns the errors: Undefined index: $result_explode[0] Undefined index: $result_explode[1] However I'm not sure how to define these (I'm self learning on a step curve)