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"

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.

@tcollins, just include

ob_start();

at the top of the page.
ob_start()

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

then how would go to another page without header?

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.