Jump to content

What did I do wrong in my code, Header problem, HELP!!


darkk58

Recommended Posts

ok I have been getting this error in every single page that has a header that redirect the user to a different page

 

Error:

 

Warning: Cannot modify header information - headers already sent by (output started at /home/abdulrab/public_html/Kasco/storeuser/user_register.php:2) in /home/abdulrab/public_html/Kasco/storeuser/user_register.php on line 54

 

for example the register page, if a user registers it will show the error not redirect him to the registration success page

 

or if they made a mistake (passwords not the same, username taken) it should redirect them to different pages but it only shows that error

 

please help

 

 

this is the register page:

 

     <?php
     
    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    ?>
     <?php

     
    // Connect to the MySQL database
    
    include "../storescripts/connect_to_mysql.php";
     
     
    //This code runs if the form has been submitted
     
    if (isset($_POST['submit'])) {
     
     
     
    //This makes sure they did not leave any fields blank
     
    if (!$_POST['firstname'] | !$_POST['surname'] | !$_POST['business_name'] | !$_POST['address1'] | !$_POST['city'] | !$_POST['postcode'] | !$_POST['telephone_number'] | !$_POST['mobile_number'] | !$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] | !$_POST['email'] ) {
     
   header("location: register_user_fail.php");
   
exit(); 
     
    }
     
     
     
    // checks if the username is in use
     
    if (!get_magic_quotes_gpc()) {
     
    $_POST['username'] = addslashes($_POST['username']);
     
    }
     
    $usercheck = $_POST['username'];
     
    $check = mysql_query("SELECT username FROM user WHERE username = '$usercheck'")
     
    or die(mysql_error());
     
    $check2 = mysql_num_rows($check);
     
     
     
    //if the name exists it gives an error
     
    if ($check2 != 0) {
     
     header("location: username_is_used.php");
     
exit(); 
     
     
    } 
     
     
    // this makes sure both passwords entered match
     
    if ($_POST['pass'] != $_POST['pass2']) {
     
   header("location: password_don't_match.php");
   
exit(); 
     
    }
     
     
     
     
     
    // now we insert it into the database
     
    $insert = "INSERT INTO user (firstname, surname, business_name, address1, address2, address3, postcode, city, telephone_number, mobile_number, username, password, email)
     
    VALUES ('".$_POST['firstname']."', '".$_POST['surname']."', '".$_POST['business_name']."', '".$_POST['address1']."', '".$_POST['address2']."', '".$_POST['address3']."', '".$_POST['postcode']."', '".$_POST['city']."', '".$_POST['telephone_number']."', '".$_POST['mobile_number']."', '".$_POST['username']."', '".$_POST['pass']."', '".$_POST['email']."')";
     
  $add_member = mysql_query($insert);
if (!$add_member) echo "$insert<br/>".mysql_error();
else
{
     
      header("location: register_success.php");
      
exit(); }?>
    <?php
    }
     
    else
    {
    ?>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>User Register</title>
    <link rel="stylesheet" href="../style/style.css" type="text/css" media="screen" />
    </head>
    <body>
    <div align="center" id="wrapper">
    <?php include_once("user_login_template_header.php");?>
    <div id="content">
    <table width="100%" border="0" cellspacing="0" cellpadding="10">
    <tr>
    <td width="32%" valign="top">
    </td>
    <td width="35%" valign="top">
     
     
     
     
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
     
    <table border="0">
     
<tr><td>First Name:</td><td>
     
    <input type="text" name="firstname" maxlength="60">
     
    </td></tr>

<tr><td>Surname:</td><td>
     
    <input type="text" name="surname" maxlength="60">
     
    </td></tr>

<tr><td>Business Name:</td><td>
     
    <input type="text" name="business_name" maxlength="60">
     
    </td></tr>

<tr><td>Address 1:</td><td>
     
    <input type="text" name="address1" maxlength="60">
     
    </td></tr>

<tr><td>Address 2:</td><td>
     
    <input type="text" name="address2" maxlength="60">
     
    </td></tr>
    
    
    <tr><td>Address 3:</td><td>
     
    <input type="text" name="address3" maxlength="60">
     
    </td></tr>
    

<tr><td>Postcode:</td><td>
     
    <input type="text" name="postcode" maxlength="9">
     
    </td></tr>
    
    
      <tr><td>City:</td><td>
     
    <input type="text" name="city" maxlength="60">
     
    </td></tr>
    

<tr><td>Telephone Number:</td><td>
     
    <input type="text" name="telephone_number" maxlength="12">
     
    </td></tr>
    
    <tr><td>Mobile Number:</td><td>
     
    <input type="text" name="mobile_number" maxlength="12">
     
    </td></tr>

    <tr><td>Username:</td><td>
     
    <input type="text" name="username" maxlength="60">
     
    </td></tr>
     
    <tr><td>Password:</td><td>
     
    <input type="password" name="pass" maxlength="25">
     
    </td></tr>
     
    <tr><td>Confirm Password:</td><td>
     
    <input type="password" name="pass2" maxlength="25">
     
    </td></tr>
     
  <tr><td>Email:</td><td>
     
    <input type="email" name="email" maxlength="60">
     
    </td></tr>
    <tr><th colspan=2><input type="submit" name="submit"
    value="Register"></th></tr> </table>
     
    </form>
     
     
     
    <br />
    </p>
    <p><br />
    </p></td>
    <td width="33%" valign="top">
    </td>
    </tr>
    </table>
     
    </div>
    <?php include_once("../footer.php");?>
    </div>
    </body>
    </html>
    <?php
     
    }
    ?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.