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 = "admin@mysite.us"; // 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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

Thanks! I figured it out. For some reason I was putting the $link var in the mysql_query instead of the actual $sql variable.

 

I got it working. Thanks guys. And GOD php is such a little girl whining about some whitespace! They need to fix that!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Oh ok. Thanks for the info.

 

So now I have another question. I need to set a cookie after the database operations and the email has been sent. I cant do this because of that, I will get header errors.

So how can I do this?

 

Thanks!

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.