cleartango Posted November 24, 2009 Share Posted November 24, 2009 Hi I have a php form processing script set up. When my form is submitted, my users should be transferred to a webpage depending on what answer they give to a question, however they are currently seeing the following error message. Warning: Cannot modify header information - headers already sent by (output started at /home/barf1/public_html/anothertry4.php:3) in /home/barfutu1/public_html/anothertry4.php on line 76 Any ideas what I need to do to rectify this situation? Does my code need tweaking? And if so HOW? php code is enclosed below: 1. <?php 2. ini_set("display_errors", "1"); 3. error_reporting(E_ALL); 4. 5. $to = "emailaddress"; 6. $to2 = "emailaddress"; 7. $to3 = "emailaddress"; 8. 9. $from = $_REQUEST['contactemail'] ; 10. $name = $_REQUEST['contactname'] ; 11. $headers = "From: $from"; 12. $subject = "Request for Conference Places in York on Dec 10"; 13. 14. $fields = array(); 15. $fields{'contactname'} = " Contact Name"; 16. $fields{'contactemail'} = " Contact Email"; 17. $fields{'contactphone'} = " Contact Phone"; 18. $fields{'contactaddress'} = " Contact Address"; 19. $fields{'organisation'} = " Organisation"; 20. $fields{'delegate1name'} = "Del 1 NAME"; 21. $fields{'delegate1job'} = "Del 1 JOB"; 22. $fields{'delegate1email'} = " Del 1 EMAIL"; 23. $fields{'delegate2name'} = "Del 2 NAME"; 24. $fields{'delegate2job'} = "Del 2 JOB"; 25. $fields{'delegate2email'} = " Del 2 EMAIL"; 26. $fields{'delegate3name'} = "Del 3 NAME"; 27. $fields{'delegate3job'} = "Del 3 JOB"; 28. $fields{'delegate3email'} = " Del 3 EMAIL"; 29. $fields{'delegate4name'} = "Del 4 NAME"; 30. $fields{'delegate4job'} = "Del 4 JOB"; 31. $fields{'delegate4email'} = " Del 4 EMAIL"; 32. $fields{'delegate5name'} = "Del 5 NAME"; 33. $fields{'delegate5job'} = "Del 5 JOB"; 34. $fields{'delegate5email'} = " Del 5 EMAIL"; 35. $fields{'delegate6name'} = "Del 6 NAME"; 36. $fields{'delegate6job'} = "Del 6 JOB"; 37. $fields{'delegate6email'} = " Del 6 EMAIL"; 38. $fields{'delegate7name'} = "Del 7 NAME"; 39. $fields{'delegate7job'} = "Del 7 JOB"; 40. $fields{'delegate7email'} = " Del 7 EMAIL"; 41. $fields{'delegate8name'} = "Del 8 NAME"; 42. $fields{'delegate8job'} = "Del 8 JOB"; 43. $fields{'delegate8email'} = " Del 8 EMAIL"; 44. $fields{'delegate9name'} = "Del 9 NAME"; 45. $fields{'delegate9job'} = "Del 9 JOB"; 46. $fields{'delegate9email'} = " Del 9 EMAIL"; 47. $fields{'delegate10name'} = "Del 10 NAME"; 48. $fields{'delegate10job'} = "Del 10 JOB"; 49. $fields{'delegate10email'} = " Del 10 EMAIL"; 50. $fields{'payment'} = " Payment"; 51. $fields{'terms'} = "Terms"; 52. 53. 54. $body = "Request for Conference Places in York on Dec 10:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } 55. 56. $headers2 = "From: emailaddress"; 57. $subject2 = "Managing the Evening and Night-time Economy in Yorkshire and Humber"; 58. $autoreply = "Thank you for your reservation for the 'Managing the Evening and Night-time Economy in Yorkshire and Humber' conference. 59. 60. Your conference places will be confirmed once we have received your payment. Conference details and a conference preference questionnaire will be sent to you shortly. 61. 62. If you have chosen to pay by BACS and you do NOT receive a proforma within 24 hours or if you have any questions, please contact us on emailaddress"; 63. 64. $send = mail($to, $subject, $body, $headers); 65. $send2 = mail($from, $subject2, $autoreply, $headers2); 66. $send3 = mail($to2, $subject, $body, $headers); 67. $send4 = mail($to3, $subject, $body, $headers); 68. 69. if($payment=="bacs") 70. {header("Location: url"); exit(); } 71. elseif($payment=="card") 72. {header("Location: url"); exit(); } 73. else 74. {header("Location: url"); exit(); } 75. 76. ?> Would be very grateful for any help Mick Edit/Delete Message Quote Link to comment https://forums.phpfreaks.com/topic/182736-php-form-processing-not-sure-how-to-tackle-an-error-message/ Share on other sites More sharing options...
mikesta707 Posted November 24, 2009 Share Posted November 24, 2009 The error tells you where the output was started. It seems to have started on line 3. Make sure you delete any whitespace, as whitespace counts as output and will make any header attempts not work. Also, you should put your code in code tags Quote Link to comment https://forums.phpfreaks.com/topic/182736-php-form-processing-not-sure-how-to-tackle-an-error-message/#findComment-964460 Share on other sites More sharing options...
cleartango Posted November 24, 2009 Author Share Posted November 24, 2009 Thanks Have got rid of whitespace as you suggested, which works...thanks...only there seems to be a new issue now... When it gets to this: 69. if($payment=="bacs") 70. {header("Location: url"); exit(); } 71. elseif($payment=="card") 72. {header("Location: url"); exit(); } 73. else 74. {header("Location: url"); exit(); } even if payment =="bacs" or "card" it just does the action required if neither of these is true, which in this case means returning the form for user to complete anew. Any thoughts on why this is happening or how to tackle it? Thanks Mick Quote Link to comment https://forums.phpfreaks.com/topic/182736-php-form-processing-not-sure-how-to-tackle-an-error-message/#findComment-964467 Share on other sites More sharing options...
mikesta707 Posted November 24, 2009 Share Posted November 24, 2009 hmm, echo $payment before those if statements ( and comment out the headers) and see what the variable holds. If it doesn't hold what you expect it to you will have to analyze any code before those if statements (or post it here) that alters the $payment variable (or sets it) Quote Link to comment https://forums.phpfreaks.com/topic/182736-php-form-processing-not-sure-how-to-tackle-an-error-message/#findComment-964470 Share on other sites More sharing options...
cleartango Posted November 24, 2009 Author Share Posted November 24, 2009 Thanks mikesta Sorry. Can you explain a little simpler...am a complete newbie to this...and am not sure how to do what you're suggesting...just treat me as an idiot who needs step by step instructions and i'll get there!!! Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/182736-php-form-processing-not-sure-how-to-tackle-an-error-message/#findComment-964476 Share on other sites More sharing options...
cleartango Posted November 24, 2009 Author Share Posted November 24, 2009 i've posted all the php code which processes the payment variable. This is taken from the html form: <tr> <td colspan="3" class="labelcell" width="400"><font size="2"><label for="card">Debit/Credit card</label></font></td> <td> <input type="radio" name="payment" id="payment" value="card" tabindex="36"></td> </tr> <tr> <td colspan="3" class="labelcell"><font size="2"><label for="bacs">BACS transfer</label></font></td> <td><input type="radio" name="payment" id="payment" value="bacs" tabindex="37"></td> </tr> Hope this helps!!! mick ; ) Quote Link to comment https://forums.phpfreaks.com/topic/182736-php-form-processing-not-sure-how-to-tackle-an-error-message/#findComment-964479 Share on other sites More sharing options...
mikesta707 Posted November 24, 2009 Share Posted November 24, 2009 just do echo $payment; before the if statements Quote Link to comment https://forums.phpfreaks.com/topic/182736-php-form-processing-not-sure-how-to-tackle-an-error-message/#findComment-964502 Share on other sites More sharing options...
cleartango Posted November 24, 2009 Author Share Posted November 24, 2009 Thanks!! the user enters payment type as shown in the html based on one of two checkbox. <tr> <td colspan="3" class="labelcell" width="400"><font size="2"><label for="card">Debit/Credit card</label></font></td> <td> <input type="radio" name="payment" id="payment" value="card" tabindex="36"></td> </tr> <tr> <td colspan="3" class="labelcell"><font size="2"><label for="bacs">BACS transfer</label></font></td> <td><input type="radio" name="payment" id="payment" value="bacs" tabindex="37"></td> </tr> it's currently returning as if no payment is submitted. I've added in echo $payment; but it's not giving me any info, however as it's taking the action as if no payment type submitted i'm guessing it's not using that info as it should. i added this into the code ini_set("display_errors", "1"); error_reporting(E_ALL); this tells me Notice: Undefined variable: payment in /home/barfutu1/public_html/anothertry4.php on line 69 Notice: Undefined variable: payment in /home/barfutu1/public_html/anothertry4.php on line 70 Notice: Undefined variable: payment in /home/barfutu1/public_html/anothertry4.php on line 72 Warning: Cannot modify header information - headers already sent by (output started at /home/barfutu1/public_html/anothertry4.php:69) in /home/barfutu1/public_html/anothertry4.php on line 75 Am a newbie at this, so how do I define the $payment variable? what's the code for that? I would have thought that the variable would be defined when the user checks a checkbox and then used to go to the correct url. Despite what the code says all the urls are different. Thanks guys!!! Mick Quote Link to comment https://forums.phpfreaks.com/topic/182736-php-form-processing-not-sure-how-to-tackle-an-error-message/#findComment-964674 Share on other sites More sharing options...
cleartango Posted November 24, 2009 Author Share Posted November 24, 2009 Thanks guys! I added $payment=$_POST['payment']; ..and this has done the trick. Couldn't be happier!! Quote Link to comment https://forums.phpfreaks.com/topic/182736-php-form-processing-not-sure-how-to-tackle-an-error-message/#findComment-964689 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.