I have created an HTML form
for uploading the email
through input[type="text"]
in phpMyAdmin
. I have also created a button for adding more input fields for those users who have more than one email ID. By default it shows one input field but when we have to upload more than one email ID and click add email one remove button
is also generated for removing that field. For this functionality, I have used JavaScript
. When we finish to adding the emails then we have to submit the data. This will redirect to another page i.e. submit_data.php
for handling the backend queries. Now in this, I have created a for loop
for multiple input data, two more variables I have also added for the member name
and date
as I have those rows in my table.
My database
name is tui_test
The table
name is member_email
I have the following rows
in my table-
sno, member_name, member_email, date_upload
I error I have seeing after submit the form is-
Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn’t match number of bind variables in D:XAMPPhtdocsachievementtestingsubmit_data.php on line 30
Following are the submit_data.php
page for handling the backend queries-
<?php
if ($_SERVER['REQUEST_METHOD']=='POST') {
// Database connection settings
$servername = "localhost";
$username = "root";
$password = "";
$database = "tui_test";
// Create connection
$conn = new mysqli($servername, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Email start
// Get the email data
$emails = $_POST['email'];
$upload_name = 'name';
date_default_timezone_set('Asia/Kolkata');
$date = date('Y-m-d H:i:s');
// Prepare SQL statement to insert data into table "member_email"
$sqlEmail = "INSERT INTO member_email (member_name, member_email, date_upload) VALUES (?, ?, ?)";
$stmt1 = $conn->prepare($sqlEmail);
// Insert each email and date into the table
for ($i = 0; $i < count($emails); $i++) {
$stmt1->bind_param("ss", $upload_name, $emails[$i], $date);
$stmt1->execute();
}
// Close the statement and connection
$stmt1->close();
// Email end
}
?>