Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

css / php error

  • 28-03-2009 04:12PM
    #1
    Registered Users, Registered Users 2 Posts: 757 ✭✭✭


    I have the following code on my page. When it is just the php it works perfectly. However when I add the html to apply the css it gives me this error:
    Warning: Cannot modify header information - headers already sent by (output started at /home/jer/domains/jerlane.com/public_html/Live/changePassword.php:12) in /home/jer/domains/jerlane.com/public_html/Live/changePassword.php on line 55
    

    THe code of the page is this:
    <!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" />
    <link rel="stylesheet" type="text/css" href="styles/stylesheet.css" />
    <title>Carbon Metic Calculator - Insufficent Access</title>
    </head>
    
    <body>
    
    <div class="wrapper">
    <p align="center"> <img align="middle" src="images/HeaderOnly.jpg" /></p>
    </div>
    
    <?php
    if(!isset($_COOKIE["user"]))
    header('location:insufficientAcc.php');
    $con=mysql_connect("localhost","jer_test","group11");
    if(!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
    $db_selected = mysql_select_db('jer_test', $con);
    if (!$db_selected){
    die ('Can\'t use jer_test : ' . mysql_error());
    }
    $mypassword=$_POST['mypassword']; 
    $newpassword=$_POST['newpassword']; 
    $newpasswordc=$_POST['newpasswordc'];
    $mypassword=stripslashes($mypassword);
    $newpassword=stripslashes($newpassword);
    $newpasswordc=stripslashes($newpasswordc);
    $mypassword=mysql_real_escape_string($mypassword);
    $newpassword=mysql_real_escape_string($newpassword);
    $newpasswordc=mysql_real_escape_string($newpasswordc);
    $user=$_COOKIE["user"];
    $result=mysql_query("SELECT password FROM members WHERE username='$user'",$con);
    $row=mysql_fetch_array($result);
    $existingP=$row["password"];
    $priv=$row["privilage"];
    if($newpassword!=""){
    if($mypassword!=$newpassword){
    if($existingP==$mypassword){
    if($newpassword==$newpasswordc){
    mysql_query("UPDATE members SET password = '$newpassword' WHERE username = '$user'");
    header('location:passChangeConfirm.php');
    }
    
    else{
    echo "One of the entries of the new password was incorrect. Please click <a href=\"http://www.jerlane.com/Live/empChangePass.php\"> here</a> to try again";
    }
    }
    else{
    
    header('location:insufficientAcc.php');
    }
    }
    else{
    echo "Your old and new passwords are the same. Make them different. Please click <a href=\"http://www.jerlane.com/Live/empChangePass.php\"> here</a> to try again";
    }
    
    }
    else{
    echo "You must have a password! Please click <a href=\"http://www.jerlane.com/Live/empChangePass.php\"> here</a> to try again";
    }
    ?>
    
    </body>
    </html>
    
    

    Please help, this has me baffled for about an hour now...


Comments

  • Closed Accounts Posts: 1,200 ✭✭✭louie


    this should above all the code:
    [php]
    <?php
    if(!isset($_COOKIE["user"]))
    header('location:insufficientAcc.php');
    :::::::::::::::::::::::::::::::::::::::::
    [/php]

    or add
    [php]
    ob_start();
    [/php]
    at the top of the page so no content is written to the browser before any checks are made...


  • Registered Users, Registered Users 2 Posts: 21,278 ✭✭✭✭Eoin


    I don't know PHP, but my guess is that you can't do this stuff:
    [php]header('location:passChangeConfirm.php');[/php]
    once you have written HTML to the page.

    I am not a fan of having big blocks of ASP or PHP in the middle of a document. I would move as much of it as possible to the top of the page so you can separate your HTML and PHP better.


  • Registered Users, Registered Users 2 Posts: 757 ✭✭✭Signpost


    how can i split the code that only the echo's would be surrounded by the <div>??


  • Registered Users, Registered Users 2 Posts: 21,278 ✭✭✭✭Eoin


    Instead of doing an echo, write to a variable instead.


  • Registered Users, Registered Users 2 Posts: 757 ✭✭✭Signpost


    good thinking! i likes it!


  • Advertisement
Advertisement