Here’s my code for registerFormOne.php:
<html>
<head>
<title>Registration Form - 1 of 2</title>
</head>
<body>
<h1>Registration - Part 1 of 2</h1>
<p>Please fill in all the required information before submitting the information.</p>
<form action="registerFormTwo.php" method="post">
First Name:<input type="text" name="firstName" /><br /><?php session_start(); $_SESSION['firstName'] = firstName; ?>
Last Name:<input type="text" name="firstName" /><br /><?php session_start(); $_SESSION['firstName'] = firstName; ?>
Age:<input type="text" name="firstName" /><br /><?php session_start(); $_SESSION['firstName'] = firstName; ?>
Date of Birth:<input type="text" name="firstName" /><br /><?php session_start(); $_SESSION['firstName'] = firstName; ?>
<input type="submit" />
</form>
</body>
Here’s the error I’m getting:
Warning: session_start() [function.session-start]: Cannot send session cookie – headers already sent by (output started at C:\XAMPP\xampp\htdocs\registerFormOne.php:10) in C:\XAMPP\xampp\htdocs\registerFormOne.php on line 10
What could be the error? Also, I’m not sure where I’m supposed to save a value to a SESSION. In ASP, I would put it in the btn_Click method; but here in PHP it’s a whole other world.
Thanks a bunch guys. 🙂
First of all session_start() causes a cookie to be sent to the browser – it needs to be called before you’ve sent ANY OTHER output. Because you are outputting HTML before you make the call, you’re getting the error.
Secondly, you only need to call it once.