0

I have created a contact form in which fields are generated via an ACF repeater field in my custom post type.

I can get the rest of the form to send however im not sure how to go about the PHP side of things to submit the repeater fields?

here's what I have so far:

HTML:

<label for="<?php the_sub_field('product_name'); ?>"><?php the_sub_field('product_name'); ?> ($<?php the_sub_field('product_price'); ?>)</label>
<input id="<?php the_sub_field('product_name'); ?>" type="number" name="" value="0" />

PHP:

<?php
// Get data
$orderbusin = $_POST[“orderbusin”];
$ordercontac = $_POST[“ordercontac”];
$orderemail = $_POST[“orderemail”];
$ordernumber = $_POST[“ordernumber”];// Database connection
$conn = mysqli_connect(“Database Host”,”Database Username”,”Database Password”,”Database Name”);
if(!$conn) {
die(‘Problem in database connection: ‘ . mysql_error());
}// Data insertion into database
$query = “INSERT INTO ‘Database Name’.’Table Name’ ( ‘orderbusin’, ‘ordercontac’, ‘orderemail’, ‘ordernumber’ ) VALUES ( $orderbusin, $ordercontac, $orderemail, $ordernumber )”;
mysqli_query($conn, $query);// Redirection to the success page
header(“Location: http://example.com/thank-you-for-your-order/“);
?>
Lajos Arpad
  • 53,986
  • 28
  • 88
  • 159
Agxer
  • 41
  • 4
  • **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/5741187) – Dharman Jan 20 '22 at 11:57

0 Answers0