0

There are quite a few solutions available for this error but none seems to be working for me. I am a new php developer and trying to create web site using php programs.

The error I'm getting is "Warning: Cannot modify header information - headers already sent by (output started at /home/influss/public_html/Influsstest/hiremain.php:39) in /home/influss/public_html/Influsstest/hiremain.php on line 74"

I have checked the line no. 39 and do not find any whitespace before or after the php. also there are no white spaces in the beginning or the end of the program but still I'm getting this error.

the code is as follows:

`

<!doctype html>
<html><!-- InstanceBegin template="/Templates/registrtion.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>Hire Main</title>
<!-- InstanceEndEditable -->
    <link href="/css/styles-reg.css" rel="stylesheet" type="text/css" media="all">
    <link href="/css/reg.css" rel="stylesheet" type="text/css" media="all"/>
    <link href='http://fonts.googleapis.com/css?family=Roboto:400,500' rel='stylesheet' type='text/css'>
    <link href='http://fonts.googleapis.com/css?family=Roboto+Condensed:400,700' rel='stylesheet' type='text/css'>
    <link href='http://fonts.googleapis.com/css?family=Raleway:400,600,900,700' rel='stylesheet' type='text/css'>
    <link href='http://fonts.googleapis.com/css?family=Slabo+13px' rel='stylesheet' type='text/css'>
    <link href='http://fonts.googleapis.com/css?family=Rokkitt:400,700' rel='stylesheet' type='text/css'>
    <!-- InstanceBeginEditable name="head" -->
        <link href="css/styles.css" rel="stylesheet" type="text/css" media="all">
    <!-- InstanceEndEditable -->
</head>
<body>
    <div id="wrapper">
        <div id="top">
            <div id = "logo">
                <img src="images/logo2.jpg">
            </div>
            <div id = "social-media">
                <p>For additional information<br>Call Phone No.</p>
                <ul>
                    <li><a href="http://wwww.facebook.com"><img src="/images/icons/facebook1.png"></a></li>
                    <li><a href="http://wwww.twitter.com"><img src="/images/icons/twitter1.png"></a></li>
                    <li><a href="http://wwww.linkedin.com"><img src="/images/icons/linkedin1.png"></a></li>
                    <li><a href="http://wwww.plus.google.com"><img src="/images/icons/googleplus1.png"></a></li>
                </ul>
                </div>
        </div>
<!--        <div id="Banner">
        </div>
 -->        <div id="Content-wrapper">
            <div id="content">
            <!-- InstanceBeginEditable name="content" -->
**<?php**
                    error_reporting(E_ALL); ini_set('display_errors', 'On');                
                    function renderForm($id, $error)
                    {
?>
<?php
                        if ($error != '')
                        {
                            echo '<div style="margin:0 200px;padding:4px; color:red ;font-weight:bold;">'.$error.'</div>';
                        }
?>
                        <form action="hiremain.php" method="post" class="newreg">
                            <fieldset class="row1">
                                <p>
                                <label class="labelstyle">Enter Registration ID: *</label>
                                <input type="text" name="regid" value="<?php echo $id;?>"/>
                                </p>
                            </fieldset>
                            <p></p>
                            <input class="button1" type="submit" name="submit" value="Get Details">
                        </form>
                        <p></p>
<?php
                    }
?>
<?php
                    include('connect.php');
                    if (isset($_POST['submit']))
                    { 
                        $id = $_POST['regid'];
                        $sql = "Select * from hirefinal where hr_id = '$id'";
                        $result = mysql_query($sql) or die(mysql_error()); 
                        $total_results = mysql_num_rows($result);
                        if ($total_results > 0)
                        {
                            header('location:hireedit.php?regid='.$id);
                        }
                        else
                        {
                            $id = $_POST['regid'];
                            $sql = "Select * from hirefinal where hr_id = '$id'";
                            $result = mysql_query($sql) or die(mysql_error()); 
                            $total_results = mysql_num_rows($result);
                            if ($total_results > 0)
                            {
                                header("location:hireedit.php?regid=" . $id);
                            }
                            Else
                            {                   
                                $error = "Please register first";
                                renderForm($id, $error);    
                            }
                        }
                        mysql_free_result($result);
                    }
                    else
                    {
                        $error = "";
                        $id=""; 
                        renderform($id, $error);
                    }
?>
                <a href="hireent.php" class="linkstyle">Register a Request</a>
                <a href="index.html" class="linkstyle">Home</a>
                <p></p>
                <!-- InstanceEndEditable -->
            </div>
        </div>
        <div id="footer">
            <p>&copy;Copyright 2014 &bull; All rights Reserved &bull; Influss.com, Chennai, Mob: +9112345-12345, E-mail: abc@influss.com</p>
        </div>
    </div>
</body>
<!-- InstanceEnd -->
</html>

` The error happens to be in the line which is marked by *.

Request somebody help me out on this.

sgsandy
  • 11
  • 2

1 Answers1

1

You can't send headers after an html output.
You have to put them before

<!doctype html>

You can resolve this using:

 <?php
 error_reporting(E_ALL); ini_set('display_errors', 'On');                
 function renderForm($id, $error)
 {
 if ($error != '')
 {
 $problems = '<div style="margin:0 200px;padding:4px; color:red ;font-weight:bold;">'.$error.'</div>';
                    }
 }
 include('connect.php');
 if (isset($_POST['submit']))
 { 
 $id = $_POST['regid'];
 $sql = "Select * from hirefinal where hr_id = '$id'";
 $result = mysql_query($sql) or die(mysql_error()); 
 $total_results = mysql_num_rows($result);
 if ($total_results > 0)
 {
 header('location:hireedit.php?regid='.$id);
 }
 else
 {
 $id = $_POST['regid'];
 $sql = "Select * from hirefinal where hr_id = '$id'";
 $result = mysql_query($sql) or die(mysql_error()); 
 $total_results = mysql_num_rows($result);
 if ($total_results > 0)
 {
 header("location:hireedit.php?regid=" . $id);
 }
 Else
 {                   
 $error = "Please register first";
 renderForm($id, $error);    
 }
 }
 mysql_free_result($result);
 }
 else
 {
 $error = "";
 $id=""; 
 renderform($id, $error);
 }
    ?>
    <!doctype html>
    <html><!-- InstanceBegin template="/Templates/registrtion.dwt" codeOutsideHTMLIsLocked="false" -->
    <head>
    <!-- InstanceBeginEditable name="doctitle" -->
    <title>Hire Main</title>
    <!-- InstanceEndEditable -->
        <link href="/css/styles-reg.css" rel="stylesheet" type="text/css" media="all">
        <link href="/css/reg.css" rel="stylesheet" type="text/css" media="all"/>
        <link href='http://fonts.googleapis.com/css?family=Roboto:400,500' rel='stylesheet' type='text/css'>
        <link href='http://fonts.googleapis.com/css?family=Roboto+Condensed:400,700' rel='stylesheet' type='text/css'>
        <link href='http://fonts.googleapis.com/css?family=Raleway:400,600,900,700' rel='stylesheet' type='text/css'>
        <link href='http://fonts.googleapis.com/css?family=Slabo+13px' rel='stylesheet' type='text/css'>
        <link href='http://fonts.googleapis.com/css?family=Rokkitt:400,700' rel='stylesheet' type='text/css'>
        <!-- InstanceBeginEditable name="head" -->
            <link href="css/styles.css" rel="stylesheet" type="text/css" media="all">
        <!-- InstanceEndEditable -->
    </head>
    <body>
        <div id="wrapper">
            <div id="top">
                <div id = "logo">
                    <img src="images/logo2.jpg">
                </div>
                <div id = "social-media">
                    <p>For additional information<br>Call Phone No.</p>
                    <ul>
                        <li><a href="http://wwww.facebook.com"><img src="/images/icons/facebook1.png"></a></li>
                        <li><a href="http://wwww.twitter.com"><img src="/images/icons/twitter1.png"></a></li>
                        <li><a href="http://wwww.linkedin.com"><img src="/images/icons/linkedin1.png"></a></li>
                        <li><a href="http://wwww.plus.google.com"><img src="/images/icons/googleplus1.png"></a></li>
                    </ul>
                    </div>
            </div>
    <!--        <div id="Banner">
            </div>
     -->        <div id="Content-wrapper">
                <div id="content">
                    <!-- InstanceBeginEditable name="content" -->
<?php
echo $problems;
?>
                                <form action="hiremain.php" method="post" class="newreg">
                                    <fieldset class="row1">
                                        <p>
                                        <label class="labelstyle">Enter Registration ID: *</label>
                                        <input type="text" name="regid" value="<?php echo $id;?>"/>
                                        </p>
                                    </fieldset>
                                    <p></p>
                                    <input class="button1" type="submit" name="submit" value="Get Details">
                                </form>
                                <p></p>
                        <a href="hireent.php" class="linkstyle">Register a Request</a>
                        <a href="index.html" class="linkstyle">Home</a>
                        <p></p>
                        <!-- InstanceEndEditable -->
                </div>
            </div>
            <div id="footer">
                <p>&copy;Copyright 2014 &bull; All rights Reserved &bull; Influss.com, Chennai, Mob: +9112345-12345, E-mail: abc@influss.com</p>
            </div>
        </div>
    </body>
    <!-- InstanceEnd -->
    </html>
Stubborn
  • 995
  • 4
  • 17
  • 30
  • Does this line needs to be removed? Can youplease give a little more details on this? – sgsandy Nov 02 '14 at 17:33
  • @sgsandy No: you have to send the headers *before* that line - I've updated my answer with the code you should use – Stubborn Nov 02 '14 at 17:35
  • Thanks Stubborn for the answer – sgsandy Nov 02 '14 at 17:55
  • The problem is about positioning the function. By positioning the function where you have done it actually skips the whole header and body part and prints only the footer, the part which is beyond the last php. – sgsandy Nov 02 '14 at 18:36
  • The positioning of the function has to be just below the call. Anyway thanks a lot for solving my issue. – sgsandy Nov 02 '14 at 18:43
  • @sgsandy you're right, I updated my answer. You're welcome :) PS: consider using mysqli_ instead of mysql_ – Stubborn Nov 02 '14 at 18:46