redirect after SQL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
drschwartz
Forum Newbie
Posts: 12
Joined: Fri Feb 27, 2009 8:49 am

redirect after SQL

Post 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
JasonDFR
Forum Commoner
Posts: 40
Joined: Wed Jan 07, 2009 3:51 am

Re: redirect after SQL

Post 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');
 
?>
Post Reply