[PHP] Not redirecting.

Status
Not open for further replies.

Livar

Now 35% cooler!
Oct 15, 2010
846
86
Hey guys, I'm coding a Housekeeping for uber but for some reason it's not redirecting when done, it just removes the news boxes and comes up normal here's my news.php;
Code:
if (isset($_POST['content']))
{
	$title = filter($_POST['title']);
	$teaser = filter($_POST['teaser']);
	$topstory = WWW . '/images/ts/' . filter($_POST['topstory']);
	$content = filter($_POST['content']);
	$seoUrl = filter($_POST['url']);
	$category = intval($_POST['category']);
	
	if (strlen($seoUrl) < 1 || strlen($title) < 1 || strlen($teaser) < 1 || strlen($content) < 1)
	{
echo "Error, please fix, thnx.";
	}
	else
	{
		dbquery("INSERT INTO site_news (title,category_id,seo_link,topstory_image,body,snippet,datestr,timestamp) VALUES ('" . $title . "','" . $category . "','" . $seoUrl . "','" . $topstory . "','" . $content . "','" . $teaser . "','" . date('d-M-Y') . "', '" . time() . "')");
	
		 header( 'Location: http://127.0.0.1/newsdone.php' );

		exit;
	}
}

?>


Anything wrong?
 

Livar

Now 35% cooler!
Oct 15, 2010
846
86
No, it's not working, It submits the news and inserts but it gives of this and doesn't reidrect;


Code:
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\housekeeping\core.php:4) in C:\xampp\htdocs\housekeeping\news.php on line 28
 

Kryptos

prjRev.com
Jul 21, 2010
2,205
1,252
By submit_button_name I mean the name of your submit button, because you're even defining a $_POST['content'] a variable when $_POST['content'] is set...? Which makes no sense.

And check core.PHP on line 4.
header(); can't be used after an <HTML> tag, nor can it be used after you send data. And the <?PHP tag can't have a blank space behind and ?> can't have a black space after it.
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,637
2,389
I know whats happened.
You need ob_start() and ob_flush()

Here is the code you need:

PHP:
<?php
ob_start();
if (isset($_POST['content']))
{
	$title = filter($_POST['title']);
	$teaser = filter($_POST['teaser']);
	$topstory = WWW . '/images/ts/' . filter($_POST['topstory']);
	$content = filter($_POST['content']);
	$seoUrl = filter($_POST['url']);
	$category = intval($_POST['category']);
	
	if (strlen($seoUrl) < 1 || strlen($title) < 1 || strlen($teaser) < 1 || strlen($content) < 1)
	{
echo "Error, please fix, thnx.";
	}
	else
	{
		dbquery("INSERT INTO site_news (title,category_id,seo_link,topstory_image,body,snippet,datestr,timestamp) VALUES ('" . $title . "','" . $category . "','" . $seoUrl . "','" . $topstory . "','" . $content . "','" . $teaser . "','" . date('d-M-Y') . "', '" . time() . "')");
	
		 header( 'Location: http://127.0.0.1/newsdone.php' );

		exit;
	}
}
ob_flush();
?>
 
Status
Not open for further replies.

Users who are viewing this thread

Top