I am having an issue with the email portion of this code. when I submit the record it says inserted successfully inserted, but for the email I get Notice: Array to string conversion and it does not want to send the email of the products ordered to the email entered. I can not figure out what the issue is. I will keep trying different methods.
process_insert.php
<html>
<head>
<title></title>
</head>
<body>
<?php
ini_set('display_errors', 1);
error_reporting(~0);
$serverName = "localhost";
$userName = "root";
$userPassword = "";
$dbName = "blog_samples";
$conn = mysqli_connect($serverName,$userName,$userPassword,$dbName);
$rows_count = count($_POST["name"]);
for($i=0;$i<$rows_count;$i++){
// PREVENTING SQL INJECTION !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$employee_name = mysqli_real_escape_string($conn,$_POST["employee_name"][$i]);
$name = mysqli_real_escape_string($conn,$_POST["name"][$i]);
$code = mysqli_real_escape_string($conn,$_POST["code"][$i]);
$quantity = intval($_POST["quantity"][$i]);
$price = mysqli_real_escape_string($conn,$_POST["price"][$i]);
$sql = "INSERT INTO order_table ( employee_name, name, code, quantity, price)
VALUES ('$employee_name', '$name', '$code', '$quantity', '$price')";
$query = mysqli_query($conn,$sql);
}
if(mysqli_affected_rows($conn)>0) {
echo "Record add successfully";
}
$to = "test123@gmail.com";
$subject = "Supplies";
$headers = "From: user@gmail.com";
$message =
"employee_name: " . $_POST['employee_name'] . "
" ."name: ". $_POST['name'] ."
". "code: " . $_POST['code'] . "
" ."quantity: ". $_POST['quantity'] . "
". "price: " . $_POST['price'] . "";
mail($to,$subject,$message,$headers);
?>
</body>
</html>