-2
Warning: Cannot modify header information - headers already sent by (output started at /home/apexwyxa/public_html/click4jalandhar.in/u-banner.php:14) in /home/apexwyxa/public_html/click4jalandhar.in/conn.php on line 115

Above is my error and below is my PHP code

function update_name($fname, $lname, $u)
        {
            include "db.php";
            $query = "update users set firstname='$fname', lastname='$lname' where user_ID='$u'";
            $result = mysql_query($query);
            if($result)
            {
                $msg = "Name updated";  
            }
            else
            {
                $msg = "Error => ".mysql_error();   
            }
            header("location:userinfo.php?x=$msg");
        }
        function update_uname($username, $u)
        {
            include "db.php";
            $query = "update users set username='$username' where user_ID='$u'";
            $result = mysql_query($query);
            if($result)
            {
                $msg2 = "Username updated"; 
            }
            else
            {
                $msg2 = "Error => ".mysql_error();  
            }
            header("location:userinfo.php?x=$msg2");
        }
        function update_email($email, $u)
        {
            include "db.php";
            $query = "update users set email='$email' where user_ID='$u'";
            $result = mysql_query($query);
            if($result)
            {
                $msg3 = "Email updated";    
            }
            else
            {
                $msg3 = "Error => ".mysql_error();  
            }
            header("location:userinfo.php?x=$msg3");
        }
        function update_pass($old_pass, $new_pass, $u)
        {
            include "db.php";
            $xquery = "select * from users where user_ID = '$u'";
            $xresult = mysql_query($xquery);
            $xnum = mysql_num_rows($xresult);
            if($xnum>0)
            {
                while($xrow = mysql_fetch_array($xresult))
                {
                    extract($xrow);
                    if($xrow[8]!=$old_pass)
                    {
                        $msg4 = "Your current password is not correct/matching";    
                        header("location:userinfo.php?x=$msg4");
                    }
                    else
                    {
                        $query = "update users set password='$new_pass' where user_ID='$u' and password='$old_pass'";
                        $result = mysql_query($query);
                        if($result)
                        {
                            $msg4 = "Password updated"; 
                        }
                        else
                        {
                            $msg4 = "Error => ".mysql_error();  
                        }
                        header("location:userinfo.php?x=$msg4");
                    }
                }
            }
        }
  • 3
    See the `Related Section` ---------------------------------> – Anirudh Ramanathan Mar 21 '13 at 14:39
  • 1
    You cannot redirect with `header()` if _any_ output was already made. – Adrenaxus Mar 21 '13 at 14:40
  • Try to see if you have extra spaces in the end of the file after the closing tag ?> if it doesn't help try to remove closing tag all together. – Adidi Mar 21 '13 at 14:40
  • By the way, this is not going to work: `header("location:userinfo.php?x=$msg");` when `$msg` can contain any kind of character. You would need to change that (everywhere...) to something like: `header( "location:userinfo.php?x=" . urlencode($msg) );` – jeroen Mar 21 '13 at 14:52

2 Answers2

2

Have a look at this topic. Wordpress - Error: headers already sent

The reason this error occurs is when you output anything before the call to the header() function.

Community
  • 1
  • 1
llanato
  • 2,508
  • 6
  • 37
  • 59
0

You can only set header befor a single character sent to browser. Use javascript redirection instead.