Page 1 of 1

Simple Code Not Working

Posted: Tue Jun 29, 2010 2:55 pm
by jballou
Hey everyone,

I have NO idea why the following code isn't executing the header command located in the if statement. I've put a echo in there to make sure it was evaluating correctly, and that printed as expected. I've also moved the header command elsewhere to make sure it worked, which it did. But for some reason this isn't working. The SQL is also executing and putting everything in the database as expected. The only thing that doesn't work is the header command and it only fails when it's placed inside the if statement, even though the if statement is true. I've used similar code tons of times with no problems and I'm getting frustrated with this. Any ideas?

Code: Select all

<?php

if(isset($_POST['addNew'])) {
	
	require("sources/connection.php");
	
	$court_name = $_POST['model_name'];
	$court_type = $_POST['height'];
	$court_num = $_POST['weight'];
	$eye_color = $_POST['eye_color'];
	$city = $_POST['city'];
	$state = $_POST['state'];
	$country = $_POST['country'];
	
	$interview = $_POST['interview'];
	$gallery = $_POST['gallery'];
	$video = $_POST['video'];
	$test1 = $_POST['test1'];
	$test2 = $_POST['test2'];
	$test3 = $_POST['test3'];
	$test4 = $_POST['test4'];
	

	//$date_added = date ("Y-m-d H:i:s");
	
	
	$sql = "INSERT INTO tester VALUES ('', '$court_name', '$court_type', '$court_num', '$eye_color', '$city', '$state', '$country', '$interview', '$gallery', 
	'$video', '$test1', '$test2', '$test3', '$test4')";
	
	$result = $conn->query($sql) or die(mysqli_error());
	
	if($result){
		header("Location: cmsAdd.php?message=1");
	}
	else {
		echo "Update was not successful";
	}
}

?>

Re: Simple Code Not Working

Posted: Tue Jun 29, 2010 3:17 pm
by AbraCadaver
Headers might already have been sent so to see that try this at the top:

Code: Select all

error_reporting(E_ALL);
ini_set('display_errors', '1');
Also, the Location header is supposed to have an absolute URL (http://example.com/cmsAdd.php?message=1). And for completeness, you need an exit; after the header.

Re: Simple Code Not Working

Posted: Tue Jun 29, 2010 4:09 pm
by McInfo
There could be whitespace outside the PHP tags in the posted file or in connection.php.

Re: Simple Code Not Working

Posted: Wed Jun 30, 2010 12:56 pm
by jballou
@McInfo - you are exactly right. Thanks so much!