How do I redirect to another page after mysqli runs succesffully?
I have written the following in my reginsert.php. The goal is to take the variables from index.php and insert into my regdata table. After successful insert is completed, I want the user redirected to thank_you.html. Where/how would I incorporate that in the following code block?
<?php
$Database = array(
"Host" => 'myhost',
"User" => 'myuser',
"Password" => 'mypass',
"Name" => 'mydb'
);
if ($mysqli->connect_error)
{
$error = true;
echo $mysqli->connect_error;
}
else
$mysqli = new mysqli($Database['Host'], $Database['User'], $Database['Password'], $Database['Name']);
$stmt=mysqli->prepare("INSERT into regdata (Username,Password,Confpassword,Status,Salutation,Firstname,Lastname,Jobtitle,Telephone,Companyname,industry,Address,City,Country,State,PostalCode,Regtype,Interests,Hdsprovider,PasswordRemindQuestion,PasswordRemindAnswer)
VALUES(
$_POST['email_address'],
$_POST['create_password'],
$_POST['confirm_password'],
'0',
$_POST['salutation2'],
$_POST['first_naem'],
$_POST['last_name'],
$_POST['job_title'],
$_POST['telephone'],
$_POST['company_name'],
$_POST['industry'],
$_POST['address'],
$_POST['city'],
$_POST['state'],
$_POST['country'],
$_POST['state'],
$_POST['postal_code'],
$_POST['partner_customer_other'],
$_POST['interests'],
$_POST['provider_partner'],
$_POST['password_reminder_question'],
$_POST['password_reminder_answer']
)");
$stmt->execute();
$stmt->close();
?>
Also开发者_Python百科, note that my table field regid is a primary key and status is default to 0. Do I need to add regid as part of my insert statement?
Thanks, Sid
if ($stmt->execute()) {
header("Location: /path/to/thank_you.html");
}
if(mysql_affected_rows($stmt)>0)
{
header("Location: /path_of_page.html");
}
if($stmt=mysqli->prepare("INSERT into regdata ...."))
{
//Above code ....
} else
{
header ('Location: http://www.example.com/';
}
精彩评论