Я использую таблицу внутри формы HTML, и когда я ввожу данные в форму, я хочу, чтобы данные сохранялись в двух строках. В настоящее время, когда я ввожу данные, строка 1 перезаписывается строкой 2, и отображается только информация, представленная во второй строке.
<form name="contact-form" action="" method="post" id="contact-form">
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Email ID</th>
<th>Phone No</th>
<th>Comments</th>
</tr>
</thead>
<tr>
<td> <input type="text" class="form-control" name="your_name[]" placeholder="Name" required> </td>
<td> <input type="text" class="form-control" name="your_email[]" placeholder="Email" required></td>
<td> <input type="text" class="form-control" name="your_phone[]" placeholder="Phone" required></td>
<td><input type="text" class="form-control" name="comments[]" placeholder="Comments" required></td>
</tr>
<tr>
<td> <input type="text" class="form-control" name="your_name[]" placeholder="Name" required> </td>
<td> <input type="text" class="form-control" name="your_email[]" placeholder="Email" required></td>
<td> <input type="text" class="form-control" name="your_phone[]" placeholder="Phone" required></td>
<td><input type="text" class="form-control" name="comments[]" placeholder="Comments" required></td>
</tr>
</table>
<button type="submit" class="btn btn-primary" name="submit" value="Submit" id="submit_form">Submit</button>
<img src="img/loading.gif" id="loading-img">
</form>
на стороне ответа мой код выглядит так:
<?php
require_once("database_connection.php");
if((isset($_POST['your_name'])&& $_POST['your_name'] !='') && (isset($_POST['your_email'])&& $_POST['your_email'] !=''))
{
require_once("contact_mail.php");
for ($i = 0; $i<count($_POST['your_name']); $i++){
$yourName = $conn->real_escape_string($_POST['your_name'][$i]);
$yourEmail = $conn->real_escape_string($_POST['your_email'][$i]);
$yourPhone = $conn->real_escape_string($_POST['your_phone'][$i]);
$comments = $conn->real_escape_string($_POST['comments'][$i]);
$sql="INSERT INTO contact_form_info (name, email, phone, comments) VALUES ('".$yourName."','".$yourEmail."', '".$yourPhone."', '".$comments."')";
}
if(!$result = $conn->query($sql)){
die('There was an error running the query [' . $conn->error . ']');
}
else
{
echo "Thank you! We will contact you soon";
}
}
else
{
echo "Please fill Name and Email";
}
?>