Page 1 of 1

Cannot modify header?

Posted: Fri Apr 03, 2009 11:15 am
by fipp
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


I am receiving the following Error message:

Warning: Cannot modify header information - headers already sent by (output started at /home/content/d/a/v/davefipp/html/dbconnection.php:15) in /home/content/d/a/v/davefipp/html/registernext.php on line 47

I have ready online about the problem. I have heard whitespace and brackets and braces? I have no idea where my problem is? Can anyone help?

Code: Select all

 <?php
include('dbconnection.php');
 
//test to see if username is alphamuneric
$testname=$_POST[username];
    if (!eregi("([^A-Za-z0-9])",$testname)){
        
            //test for duplicate names
            $query="SELECT * FROM users WHERE username='$_POST[username]'";
            $result=mysql_query($query);
            $num=mysql_num_rows($result);
            
            if($num ==0){
 
                    //test for duplicate email
                    $query2="SELECT * FROM users WHERE email='$_POST[email]'";
                    $result2=mysql_query($query2);
                    $num2=mysql_num_rows($result2);
                
                        if($num2 ==0){
                        
                            //if emails and passwords match up
                            if(($_POST['pass']==$_POST['pass2'])&&($_POST['email']==$_POST['email2'])){
                                
                                
                                //generate random confirmation code
                                $confirm_code=md5(uniqid(rand()));
                                
                                // get rid of all html from hackers
                                $name=strip_tags($_POST['username']);
                                $email=strip_tags($_POST['email']);
                                $pass=strip_tags($_POST['pass']);
                                
                                //insert data into database
                                $sql="INSERT INTO temp SET code='$confirm_code', username='$name', email='$email', password='$pass'";
                                $result=mysql_query($sql);
                                
                                    if($result){
                                        $message="Your Confirmation link for your dream Great account. \r\n";
                                        $message.="Click on the link below to activate your account \r\n";
                                        $message.="http://www.dreamgreat.com/confirmation.php?passkey=$confirm_code";
                                        
                                        $sentmail=mail("$email",'Registration Confirmation',"$message");
                                    
                                            // if your email succesfully sent
                                            if($sentmail){
                                                header("Location:thankyou.html");
                                            
                                            }else{
                                                echo "Cannot send confirmation link to your email address";
                                                }
                                    
                                    
                                    }else{
                                        echo "Sorry we are currently unable to put your email into our database, please try again later";
                                        }
                                    
                                    
                            }else{
                                echo "Make sure your confirm password and confirm email are the same. Click the back button and re-try.";
                            }
                        
                        
                        }else{
                            echo "This email is already in use. Click the back button and register with a new email";
                        }
                
            }else{
                echo "This user name is already in use. Click the back button and register with a different user name";
                }
                    
        
    }else{
    echo "Your name must be made of letters and numbers only. Click the back button and try a new name.";
        }
 
?>

Thanks for your help!


pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.

Re: Cannot modify header?

Posted: Fri Apr 03, 2009 11:53 am
by pickle
Look in dbconnection.php, on line 15 - that's where it says the output started.

Re: Cannot modify header?

Posted: Fri Apr 03, 2009 12:17 pm
by fipp
That space before <?php is not in the file.

here is the dbconnection file

Code: Select all

<?php
//Connect To Database
$host='myhost';
$username='myusername';
$password='mypassword';
$dbname='mydatabasename';
 
//connect to database
mysql_connect($host,$username,$password) OR DIE ('Cannot connect to server');
mysql_select_db($dbname) OR DIE ('Cannot connect database');
 
 
 
 
?>

Re: Cannot modify header?

Posted: Fri Apr 03, 2009 1:49 pm
by fipp
Thanks for all of your help. I solved the problem. There was a space after ?>

I am sorry to waste your time.