Jump to content

WHY am I getting this UNNECESSARY header error!???


jdock1

Recommended Posts

I ABSOLUTELY HATE header errors! I CAN NEVER use session_start() because I ALWAYS get this error. I have looked everywhere and still cannot find a solution to my problem.

 

All I am trying to do is add session_start(). Its on the VERY first line of the page, and there is no code before it at all.

 

Here is my code:

 

<?php
session_start();
  $txnid = session_id();

if(isset($_GET['email']))
{
   
   
    /*
     * include database connection page
     */
    include("db.php");
    /*
     * insert to db
     */
    $sql = "INSERT INTO `TRANSACTIONS_TAB` (PASSWORD,USER_EMAIL,PAY_STATUS) VALUES ('$txnid','$email',0)";

    if(mysql_query($link))
    {
        echo "Session stored!";
        $subject = "Your Cash Code From mysite";
        $message = "Hello, <br/> Your cash code is ".$txnid."<br/> Please do not share with anyone. This code can only be redeemed once. Once redeemed successfully, the PayPal transaction will be initiated and payment sent to the email address you provided. If you did not recieve the payment, please contact support.  ";
        $from = "[email protected]"; // include from email address
        $headers = "From:" . $from;
        mail($email,$subject,$message,$headers);
        echo "Your cash code has been sent to your email address!";
    }
    else
    {
       echo "An unknown error has occured. Please contact support and mention error ID CCF1.";
    }
}
?>

 

Here is the errors Im getting:

 

 

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/mydock/public_html/mysite/genCashCode.php:3) in /home/mydock/public_html/mysite/genCashCode.php on line 4

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/mydock/public_html/mysite/genCashCode.php:3) in /home/mydock/public_html/mysite/genCashCode.php on line 4

An unknown error has occured. Please contact support and mention error ID CCF1.

 

I kind of now just realized it could be caused from sending the email. How can I make this work then if this is the case?

 

Thanks

Ok well I deleted the whitespace and now there are no header errors, but now Im getting the custom error message, basically meaning the database was unable to insert anything and the email was not able to be sent.

 

I added mysql_errno and got 1064. Now I cant find any where online what the error is for this code.

 

Does anybody know what the mysql error number 1064 is?

 

Thanks!

The problem is not php, its a requirement of the HTTP protocol. Headers must be output before any content is sent (white-space is content as far as the protocol is concerned.)

 

The error is not unnecessary. It tells you two things -

 

1) The session_start failed, so none of your $_SESSION variables will work,

 

2) That you are outputting something before a header and where it is being output at so that you can find it and eliminate it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.