Page 1 of 1

Can't get header(Location: ) to redirect.

Posted: Fri Dec 23, 2011 2:07 am
by orbdrums
I'm not sure if this is a config problem or a code problem. I get no errors but the php line of code is not redirecting. As always, thanks in advance for any help.

Code: Select all

<?php

$objConnect = mysql_connect('localhost','user') or die(mysql_error());
$objDB = mysql_select_db("test");

	for($i=0;$i<count($_POST["chkDel"]);$i++)
	{
		if($_POST["chkDel"][$i] != "")
		{
			$strSQL = "DELETE FROM customer WHERE CustomerID = '".$_POST["chkDel"][$i]."' ";
			$objQuery = mysql_query($strSQL);
		}
	}

header("Location: http://localhost:8888/test/php_mysql_checkbox/php_mysql_checkbox1.php");
mysql_close($objConnect);
?>
Clark

Re: Can't get header(Location: ) to redirect.

Posted: Fri Dec 23, 2011 4:09 am
by mikeashfield
Excerpt from PHP: header - Manual
Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

Code: Select all

<html>
<?php
/* This will give an error. Note the output
 * above, which is before the header() call */
header('Location: http://www.example.com/');
?>

Re: Can't get header(Location: ) to redirect.

Posted: Fri Dec 23, 2011 11:37 am
by orbdrums
I read the php manual but I missed the blank line part. When I moved the line of code to the top of the file and removed the blank line everything worked as planned. Thanks for your help.