0

i am making a website in php all on one page. here is my script

<a href='?goto=register'>register</a>
<?php
if ($_GET['goto']=='register'){
?>
		<form name='register' method='POST' action='?goto=reg'>
		<table style='margin-left: auto; margin-right: auto; color: white; font-weight: bold;'>
		<tr><td style='text-align:center;'>First Name: <input type='text' name='first'></td></tr>
        <tr><td style='text-align:center;'>Last Name: <input type='text' name='last'></td></tr>
        <tr><td style='text-align:center;'>Email: <input type='text' name='email'></td></tr>
        <tr><td style='text-align:center;'>Password: <input type='text' name='pass'></td></tr>
		 <tr><td style='text-align:center;'><INPUT TYPE='SUBMIT' value='Register' name='submit' id='submit'></td></tr>
		 </table>
		</form>
		<?php
	}
else if($_GET['goto']=='reg'){
		    include "dbconnect.php";
			$fname=$_POST['first'];
			$lname=$_POST['last'];
			$email=$_POST['email'];
			$email=mysql_real_escape_string($email);
			$password=$_POST['pass'];
			$password=md5($password);
			$date=date("y-m-d");
			$query="INSERT INTO members (name, lname, email, password, date) VALUES ('$fname','$lname','$email','$password','$date')";
			$result=mysql_query($query);
			if ($result){
				header("location:?goto=thankyou");
			}else{
				echo"<font color='white'>nope</font>";
			}
 }

but i keep getting the error "cannot modify header information - header already sent"

4
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by pzuurveen
0

your above code is simply fine.
what your dbconnect.php page contains?
try to include dbconnect.php page (include "dbconnect.php";) at the first line of your page.

Edited by Shanti C: n/a

0

The header gets sent before the first output. In your case
at line 1

<a href='?goto=register'>register</a>

you cant do a header call after that as you do at line 28

1

Just make sure there is no output be for your header call
(not even a white line outside your php tags)
You can rearrange your code

<!-- no white lines here -->
<?php
 
if ($_GET['goto']=='register'){
?>
		<form name='register' method='POST' action='?goto=reg'>
		<table style='margin-left: auto; margin-right: auto; color: white; font-weight: bold;'>
		<tr><td style='text-align:center;'>First Name: <input type='text' name='first'></td></tr>
        <tr><td style='text-align:center;'>Last Name: <input type='text' name='last'></td></tr>
        <tr><td style='text-align:center;'>Email: <input type='text' name='email'></td></tr>
        <tr><td style='text-align:center;'>Password: <input type='text' name='pass'></td></tr>
		 <tr><td style='text-align:center;'><INPUT TYPE='SUBMIT' value='Register' name='submit' id='submit'></td></tr>
		 </table>
		</form>
		<?php
	}
else if($_GET['goto']=='reg'){
		    include "dbconnect.php";
			$fname=$_POST['first'];
			$lname=$_POST['last'];
			$email=$_POST['email'];
			$email=mysql_real_escape_string($email);
			$password=$_POST['pass'];
			$password=md5($password);
			$date=date("y-m-d");
			$query="INSERT INTO members (name, lname, email, password, date) VALUES ('$fname','$lname','$email','$password','$date')";
			$result=mysql_query($query);
			if ($result){
				header("location:?goto=thankyou");
			}else{
				echo"<font color='white'>nope</font>";
			}
else {
     ?> <a href='?goto=register'>register</a>
<?php
      }
 }
?>

hope it helps

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.