jdock1 Posted May 30, 2012 Share Posted May 30, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/263385-why-am-i-getting-this-unnecessary-header-error/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 30, 2012 Share Posted May 30, 2012 According to the error messages, the session_start statement is on line 4 in your file and you have something being sent as output on or before line 3. What's in your file before the <?php tag? Quote Link to comment https://forums.phpfreaks.com/topic/263385-why-am-i-getting-this-unnecessary-header-error/#findComment-1349810 Share on other sites More sharing options...
jdock1 Posted May 30, 2012 Author Share Posted May 30, 2012 Absolutely nothing! Thats why I dont get it. There is nothing at all before the php tag. Just whitespace. Could that cause this?!! Quote Link to comment https://forums.phpfreaks.com/topic/263385-why-am-i-getting-this-unnecessary-header-error/#findComment-1349831 Share on other sites More sharing options...
jdock1 Posted May 30, 2012 Author Share Posted May 30, 2012 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! Quote Link to comment https://forums.phpfreaks.com/topic/263385-why-am-i-getting-this-unnecessary-header-error/#findComment-1349839 Share on other sites More sharing options...
PFMaBiSmAd Posted May 30, 2012 Share Posted May 30, 2012 mysql_error gives the textual error message. Quote Link to comment https://forums.phpfreaks.com/topic/263385-why-am-i-getting-this-unnecessary-header-error/#findComment-1349840 Share on other sites More sharing options...
jdock1 Posted May 30, 2012 Author Share Posted May 30, 2012 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! Quote Link to comment https://forums.phpfreaks.com/topic/263385-why-am-i-getting-this-unnecessary-header-error/#findComment-1349842 Share on other sites More sharing options...
PFMaBiSmAd Posted May 30, 2012 Share Posted May 30, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/263385-why-am-i-getting-this-unnecessary-header-error/#findComment-1349843 Share on other sites More sharing options...
jdock1 Posted May 30, 2012 Author Share Posted May 30, 2012 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! Quote Link to comment https://forums.phpfreaks.com/topic/263385-why-am-i-getting-this-unnecessary-header-error/#findComment-1349848 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.