Page 1 of 1

PHP form processing - getting odd error message & need fix

Posted: Mon Nov 23, 2009 9:02 pm
by cleartango
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 grateful for any help

Mick

Re: PHP form processing - getting odd error message & need fix

Posted: Mon Nov 23, 2009 10:00 pm
by cleartango
Have got rid of whitespace, which works...and now there seems to be a new issue ...

When it gets to this:

Code: [Select]
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.

Anybody have any thoughts on why this is happening or how to tackle it?

Thanks

Mick

Re: PHP form processing - getting odd error message & need fix

Posted: Tue Nov 24, 2009 7:18 am
by cleartango
Thanks!!

the user enters payment type as shown in the html based on one of two checkbox.

Code: Select all

 
<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

Code: Select all

 
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

Re: PHP form processing - getting odd error message & need fix

Posted: Tue Nov 24, 2009 8:01 am
by cleartango
Thanks guys!

I added

$payment=$_POST['payment'];

..and this has done the trick.

Couldn't be happier!!

Re: PHP form processing - getting odd error message & need fix

Posted: Tue Nov 24, 2009 8:11 am
by superdezign
Congrats. Next time, use

Code: Select all

tags around code. It'll make the code easier for us to read, and the likeliness of someone helping you will increase.