After the form's data is sent to MySQL I want to redirect the user to another page. (This will be the payment system page, but for now I do not have the URL for the payment page, so I am trying to redirect to index.php
) Unfortunately, the redirect is not working. What am I doing wrong here?
The form's data is being received by mysql database. I checked it.
PHP File:
<?php
//Only process the form if $_POST isn't empty
if (!empty( $_POST) ) {
// Connect to MySQL
$conn = mysqli_connect('localhost', 'root', 'root', 'lpw_');
// Check our connection
if (!$conn) echo 'Could not connect DB';
// Insert our data
$sql = "INSERT INTO play ( mobilenumber, mntimes, landlinenumber, lntimes,
otherphonenumber, opntimes, firstname, lastname, age, city, country, email )
VALUES ( '{$conn->real_escape_string($_POST['mobilenumber'])}',
'{$conn->real_escape_string($_POST['mntimes'])}',
'{$conn->real_escape_string($_POST['landlinenumber'])}',
'{$conn->real_escape_string($_POST['lntimes'])}',
'{$conn->real_escape_string($_POST['otherphonenumber'])}',
'{$conn->real_escape_string($_POST['opntimes'])}',
'{$conn->real_escape_string($_POST['firstname'])}',
'{$conn->real_escape_string($_POST['lastname'])}',
'{$conn->real_escape_string($_POST['age'])}',
'{$conn->real_escape_string($_POST['city'])}',
'{$conn->real_escape_string($_POST['country'])}',
'{$conn->real_escape_string($_POST['email'])}' )";
$insert = mysqli_query($conn, $sql);
// Print response from MySQL
if ($insert) {
header("Location: index.php");
} else {
die("Error: {$conn->mysql_errno} : {$conn->error}");
}
// Close DB connection
$conn->close();
}
HTML Page:
<form action="" method="post">
<div>
<label for="mobilenumber">Mobile Number *</label>
<div>
<input name="mobilenumber" type="text" id="mobilenumber" placeholder="Mobile Number">
</div>
</div>
...
//the same kind of code, only diferent values.
...
<input type="submit" name="Submit" id="Submit " value="Next step"/>