tags:

views:

51

answers:

3

Hi,

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, 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

+2  A: 
if ($stmt->execute()) {
    header("Location: /path/to/thank_you.html");
}
Stoosh
Thanks for your advice. Would the above script be a good place to include the sending of an email, or should that be done in the index page?
SidC
A: 
if($stmt=mysqli->prepare("INSERT into regdata ...."))
{
  //Above code ....
} else 
{ 
   header ('Location: http://www.example.com/';
}
aromawebdesign.com
Why is voted down?
aromawebdesign.com
A: 

if(mysql_affected_rows($stmt)>0)
{
     header("Location: /path_of_page.html");
}

Wasim
He is using MySQLi, so it would actually be $stmt->affected_rows > 0
Stoosh
if($mysqli->affected_rows > 0)
Wasim
@Stoosh: MySQLi allows `mysqli_affected_rows` as well: http://www.php.net/manual/en/mysqli.affected-rows.php
Hello71
Yes, I know however I was just trying to keep it inline with the previous coding style of calling it the OO way rather than procedural.
Stoosh