Redirect not working

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
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Redirect not working

Post by mohson »

Ive made some changes to this code and now for some reason it will not redirirect back to upeople.php as it did before - I cant see anything wrong with it does anyone know why its not redirecting and im getting a blank screen instead?

Code: Select all

<?php
/* Connecting, selecting database */
connection code


  
$sql = 

			"INSERT INTO people 
			
			(person_id, salutation, 
			firstname, surname, organisation, role, 
			address1, address2, city, postcode, telephone, 
			mobile, fax, dateoflastcontact, datecontactagain, 
			email)
			
			VALUES 
			
			('$person_id','$salutation',
			'$firstname','$surname', '$organisation', 
			'$role', '$address1', '$address2', '$city', 
			'$postcode', '$telephone', '$mobile', '$fax', 
			'$dateoflastcontact', '$datecontactagain', 
			'$email') "; 

$result = mysql_query($sql,$link) or die ( mysql_error($link));;
 header ("location: http://editweb.soi.city.ac.uk/organisat ... people.php");
?>
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Line 3 - "Connection code" should be annoted by // ?
You may also want to replace the double ; at line 26 with just one ;
For error like this I find it useful while debugging to include the following lines at the top of the php

Code: Select all

<?php

error_reporting(E_ALL);
ini_set('display_errors', TRUE);

// Rest of code
?>
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

at line 3 I just put that in connection code in on this forum because I could be bothered to post the entire code.
at line 26 isnt a problem as it works fine with my other coding and worked fine before .

can anyone else see what might be going wrong???
gskaruz
Forum Newbie
Posts: 8
Joined: Mon Mar 15, 2004 6:45 am

Post by gskaruz »

Try add this:

Code: Select all

Header("HTTP/1.0 302 Redirect");
Header("location: http://editweb.soi.city.ac.uk/organisat ... people.php");
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Try

Code: Select all

header("Location: url");
with Location having initial uppercase.
If this does not work and you have not added the two lines I mentioned before add them and let us know the result.
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

sorry guys tried both methods and they do not work - its strange because this worked perfectly before I tried to publish my work on my University server which requires all kinds of strange functions as they have their own content management system.

Here is the warning I get when the blank page appears:
Warning: Cannot modify header information - headers already sent by (output started at /export/TSG-Z/web-source/organisation/pl/CMS/processpeople.html:2) in /export/TSG-Z/web-source/organisation/pl/CMS/processpeople.html on line 34
its as if my header is conflicting with the university header but I have removed there heade code from my code.

any ideas anyone - im going to speak to our tech support team but it would be wonderful if someone could help me before then.[/quote]
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Basically, the error means that out put of the page has already started before you redirect. Chexk that you have no stray whitespace (or any other output) anywhere before the redirect.
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

Nah I definately dont - heres the code

Code: Select all

<?php

error_reporting(E_ALL);ini_set('display_errors', TRUE);


/* Connecting, selecting database */
$link = mysql_connect("****", "****", "****")
   or die("Could not connect : " . mysql_error());
mysql_select_db("contact_management_system",$link) or die("Could not select database");


  
$sql = 

			"INSERT INTO people 
			
			(person_id, salutation, 
			firstname, surname, organisation, role, 
			address1, address2, city, postcode, telephone, 
			mobile, fax, dateoflastcontact, datecontactagain, 
			email)
			
			VALUES 
			
			('$person_id','$salutation',
			'$firstname','$surname', '$organisation', 
			'$role', '$address1', '$address2', '$city', 
			'$postcode', '$telephone', '$mobile', '$fax', 
			'$dateoflastcontact', '$datecontactagain', 
			'$email') "; 

$result = mysql_query($sql,$link) or die ( mysql_error($link));
header ("location: http://editweb.soi.city.ac.uk/organisat ... people.php");
?>
Could it be anything else


the funny thing is I do exactly the same here and it works fine:

code below

Code: Select all

<?php
/* Connecting, selecting database */
$link = mysql_connect("*******", "*****", "******")
   or die("Could not connect : " . mysql_error());

mysql_select_db("contact_management_system",$link) or die("Could not select database");
 $sql = "INSERT INTO organisations (org_id,person_id, orgname, web_url, sector, location, current_placement, no_ofstudents, notes ) VALUES ('$org_id','$person_id','$orgname','$web_url','$sector', '$location', '$current_placement', '$no_ofstudents', '$notes')";
 $result = mysql_query($sql,$link) or die ( mysql_error($link));;
 header ("location: http://www.soi.city.ac.uk/organisation/pl/CMS/Uorgs.php");
?>
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

you have nothing, whatsoever before the opening <?php tag?
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

May be obvious but I have to ask.
Are you sure you do not "echo" or print anything before the redirect?

One method to tell...

Code: Select all

<?php
echo("[");
//connection code
//All code before header
echo("]");
header("Location:url");
?>
Now we know this will fail, but do we get anything between the "[" and "]" (Check with view source). If yes, even if it is a space we need to track it down and get rid of it. (We can then get rid of the echo's so it actually works).
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

im putting money on output already being started before the <?php tag, because the error message is stating that the output has started on line 2.
Post Reply