I want my form to insert the data into an SQL database using PHP which is a separate file while, going to another webpage once the form has been submitted.
<form action="http://localhost:8888/phpv1/studentadded.php" method="post">
<input type="submit" name="submit" value="Send">
Currently I use the following code which works in the sense that it invokes the PHP and causes it to submit the data into the SQL database. However it goes to a blank webpage (the page of the PHP) instead of going to an alternate webpage. What code should I add so that when submitted it goes to an alternate web page? Thanks :)
Here is my full php script:
<?php
if(isset($_POST['submit'])){
$data_missing = array();
if(empty($_POST['email_banned'])){
// Adds name to array
$data_missing[] = 'Email';
} else {
// Trim white space from the name and store the name
$email_banned = trim($_POST['email_banned']);
}
if(empty($_POST['notes'])){
// Adds name to array
$data_missing[] = 'Notes';
} else {
// Trim white space from the name and store the name
$notes = trim($_POST['notes']);
}
if(empty($data_missing)){
require_once('mysqli_connect.php');
$query = "INSERT INTO banned_emails (id, email_banned, created_on, notes) VALUES ( NULL, ?, NOW(), ?)";
$stmt = mysqli_prepare($dbc, $query);
//i Interger
//d Doubles
//s Everything Else
mysqli_stmt_bind_param($stmt, "ss", $email_banned, $notes);
mysqli_stmt_execute($stmt);
$affected_rows = mysqli_stmt_affected_rows($stmt);
if($affected_rows == 1){
echo 'Student Entered';
header("Location: http://localhost:8888/phpv1/test2.php");
mysqli_stmt_close($stmt);
mysqli_close($dbc);
} else {
echo 'Error Occurred<br />';
echo mysqli_error();
mysqli_stmt_close($stmt);
mysqli_close($dbc);
}
} else {
echo 'You need to enter the following data<br />';
foreach($data_missing as $missing){
echo "$missing<br />";
}
}
}
?>
Have I placed the header in the right place? (I will obviously change the content of the header)