Page 1 of 1
Redirect not working
Posted: Wed Mar 30, 2005 5:20 am
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");
?>
Posted: Wed Mar 30, 2005 5:26 am
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
?>
Posted: Wed Mar 30, 2005 6:56 am
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???
Posted: Wed Mar 30, 2005 7:14 am
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");
Posted: Wed Mar 30, 2005 8:06 am
by CoderGoblin
Try
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.
Posted: Wed Mar 30, 2005 8:51 am
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]
Posted: Wed Mar 30, 2005 8:57 am
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.
Posted: Wed Mar 30, 2005 9:03 am
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");
?>
Posted: Wed Mar 30, 2005 9:09 am
by JayBird
you have nothing, whatsoever before the opening <?php tag?
Posted: Wed Mar 30, 2005 9:11 am
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).
Posted: Wed Mar 30, 2005 9:20 am
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.