Need Help !! Getting Error in sending headers
Posted: Thu Oct 23, 2003 1:44 pm
Hi I am creating a quiz module where every new user have to register before they get into the quiz page. Their Information will be stored in a database and as well as the results of the quiz. My code is as below:-
<?php
$first_name = pg_escape_string($first_name);
$last_name = pg_escape_string($last_name);
$email = pg_escape_string($email);
$birthdate = $month.$day;
$sql = "SELECT *
FROM person
WHERE first_name='$first_name' AND last_name='$last_name'
AND birthdate = '$birthdate'";
$result = pg_query($sql);
$row = pg_fetch_row($result);
if ($row == ""):
//Add
$sql = "SELECT org_id
FROM org
WHERE name = '$org'";
$result = pg_query($sql);
$row = pg_fetch_row($result);
$org_id = $row[0];
$sql = "INSERT INTO person
(first_name, last_name, email, birthdate, status, org_id)
VALUES ('$first_name', '$last_name', '$email', '$birthdate', '$status', '$org_id')";
print $sql;
$result= pg_query($sql);
header ("Location:$redirect");
setcookie ("reg_id","$person_id", 0, "/");
else:
//User exists. Send 'em back
$errstr = 'Only one person can be registered with the same name and ';
$errstr .= 'birthday. Someone has already logged in under your name. ';
$errstr .= 'If you have registered before, go to the short registration ';
$errstr .= 'form. If this is your first time, type your nickname or add ';
$errstr .= 'a middle initial in the "First Name" box.';
endif;
?>
If you can see the code in BOLD.. I cannot get the page to redirect once the user registers but instead I am getting an error like this below:-
Warning: Cannot modify header information - headers already sent by
At the end of my html page I have this piece of code which tells the page to redirect:-
Any help would be highly appreciated!!!
?>
<?php
$first_name = pg_escape_string($first_name);
$last_name = pg_escape_string($last_name);
$email = pg_escape_string($email);
$birthdate = $month.$day;
$sql = "SELECT *
FROM person
WHERE first_name='$first_name' AND last_name='$last_name'
AND birthdate = '$birthdate'";
$result = pg_query($sql);
$row = pg_fetch_row($result);
if ($row == ""):
//Add
$sql = "SELECT org_id
FROM org
WHERE name = '$org'";
$result = pg_query($sql);
$row = pg_fetch_row($result);
$org_id = $row[0];
$sql = "INSERT INTO person
(first_name, last_name, email, birthdate, status, org_id)
VALUES ('$first_name', '$last_name', '$email', '$birthdate', '$status', '$org_id')";
print $sql;
$result= pg_query($sql);
header ("Location:$redirect");
setcookie ("reg_id","$person_id", 0, "/");
else:
//User exists. Send 'em back
$errstr = 'Only one person can be registered with the same name and ';
$errstr .= 'birthday. Someone has already logged in under your name. ';
$errstr .= 'If you have registered before, go to the short registration ';
$errstr .= 'form. If this is your first time, type your nickname or add ';
$errstr .= 'a middle initial in the "First Name" box.';
endif;
?>
If you can see the code in BOLD.. I cannot get the page to redirect once the user registers but instead I am getting an error like this below:-
Warning: Cannot modify header information - headers already sent by
At the end of my html page I have this piece of code which tells the page to redirect:-
Code: Select all
<input type=hidden name="redirect" value="quiz.php">
<table cellpadding="10">
<tr><td align=center><input type=button value="Register" onClick="largeReg(document.reg);"></td></tr>
</table>
</form>?>