Page 1 of 1

redirect after SQL

Posted: Fri Feb 27, 2009 8:52 am
by drschwartz
I need to redirect to another site after storing form data to a mysql table. I read that there's no possible output that can proceed the use of a header statement. Does this include my sql-related code? What exactly does 'output' refer to?

TIA,
David

Re: redirect after SQL

Posted: Fri Feb 27, 2009 10:15 am
by JasonDFR
Output is anything that is sent to the user's browser. Including blank spaces. As long as you don't call header(); after anything is output to the user's browser, you won't have any problem.

Your SQL code should not cause any output to occur.

For example:

Code: Select all

<?php
 
$q = "SELECT * FROM table";
 
mysqli_query($dbc, $q);
 
header('Location: /thanks.php');
 
?>
The above will work.

Below will not work.

Code: Select all

<html>
 
<?php
 
$q = "SELECT * FROM table";
 
mysqli_query($dbc, $q);
 
header('Location: /thanks.php');
 
?>