Grafica Posted August 10, 2012 Share Posted August 10, 2012 Hi. I'm using xampp 1.8.0 with Windows 7 SP1, 32 bit OS, and coding HTML5 and CSS3. I'm just learning PHP, and I created a contact form for a dentist's Website, so that patients can request appointments. An email should go to the dentist and display the information that the user entered. (I only coded the 'name' and 'description' to be in the email so far, since this is just a test.) I'm using Javascript to check if the patient filled out the form properly, so I didn't use some of the code shown on pg. 332 of the book. There is an error on the first line: Parse error: syntax error, unexpected 'POST' (T_STRING), expecting ']'. Can someone tell me what's wrong? Thanks. <?php if ($_SERVER['REQUEST_METHOD] == 'POST' { body = "Name: ($POST['name']}\n\nComments: {$_POST['description']}"; $body = wordwrap($body, 70); mail('mail@yahoo.com', 'Contact Form Submission', $body, "From: {$_POST['email']}"); echo 'Thank you for your request. A member of our staff will be contacting you shortly.'; $_POST = array(); } ?> <div id="form"> <div id="contain"> <form action="EmailConf.php" method="post"> <table class="form_demo"> <tr> <td> <label>Name</label> </td> <td> <input class="input_full" type="text" id="name" name="name" required="required" /> </td> </tr> <tr> <td><label for="email"> Email </label> </td> <td> <input class="input_full" type="email" id="email" name="email" required="required" /> </td> </tr> <tr> <td> <label for="tel"> Phone </label> </td> <td> <input class="input_full" type="tel" id="tel" name="tel" required="required" /> </td> </tr> <tr> <td><label for="priority_normal"> Priority </label> </td> <td> <input type="radio" name="priority" id="priority_urgent" value="Urgent"> <label for="priority_urgent"> Urgent </label> <input type="radio" name="priority" id="priority_normal" value="Normal" checked="checked"> <label for="priority_normal"> Normal </label> </td> </tr> <tr> <td> <label for="date">Enter a date:</label> </td> <td> <input class="input_xlarge" type="text" id="date" name="date" required="required" /> <script> (function($){ var pickerOpts = { minDate: new Date(), maxDate: "+3m,", showButtonPanel: true, showOn: "button", buttonImage: "images/cal.png", }; $("#date").datepicker(pickerOpts); })(jQuery); </script> </td></tr> <tr><td>Enter a time: </td> <td><input id="time1" name="s2Time1" /> <script type="text/javascript"> $('#time1').ptTimeSelect({ popupImage: 'Select Time' }); </script> </td> </tr> <tr> <td> <label for="description"> Reason for<br /> appointment </label> </td> <td> <textarea id="description" name="description" rows="3" required="required"></textarea> </td> </tr> </table> <hr /> <p class="clearfix"> <input type="submit" value="Submit" class="float_left" /> <input type="reset" value="Reset" class="float_right"> </p> </form> Link to comment Share on other sites More sharing options...
Edward Posted August 10, 2012 Share Posted August 10, 2012 if ($_SERVER['REQUEST_METHOD] == 'POST') Replace first line with this. Is a parse error on this line also body = "Name: ($POST['name']}\n\nComments: {$_POST['description']}"; Replace with body = "Name: ($_POST['name']}\n\nComments: {$_POST['description']}"; 1 Link to comment Share on other sites More sharing options...
Grafica Posted August 10, 2012 Author Share Posted August 10, 2012 Thanks, Edward. I'm still getting an error on the body = "Name: ($_POST['name']}\n\nComments: {$_POST['description']}"; Parse error: syntax error, unexpected '=' Link to comment Share on other sites More sharing options...
Larry Posted August 10, 2012 Share Posted August 10, 2012 You have an error there: ( before $_POST when it should be { 1 Link to comment Share on other sites More sharing options...
Grafica Posted August 10, 2012 Author Share Posted August 10, 2012 Thanks. I changed it, but it's still returning the same error on the same line. Link to comment Share on other sites More sharing options...
Edward Posted August 10, 2012 Share Posted August 10, 2012 What is the error message now, can you confirm with us what you have on that line? Link to comment Share on other sites More sharing options...
Grafica Posted August 10, 2012 Author Share Posted August 10, 2012 body = "Name: {$_POST['name']}\n\nComments: {$_POST['description']}"; Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\RequestAppt2.php on line 56 Link to comment Share on other sites More sharing options...
Edward Posted August 10, 2012 Share Posted August 10, 2012 Ah you need to put a $ sign in front of body. Link to comment Share on other sites More sharing options...
Edward Posted August 10, 2012 Share Posted August 10, 2012 It's funny I missed the { and Larry missed the $. Link to comment Share on other sites More sharing options...
Grafica Posted August 10, 2012 Author Share Posted August 10, 2012 Thanks, Edward. Wow, I must need new glasses! That worked, but I filled out the form, and did not get an email. (I changed 'mail@yahoo.com' to my real email address.) Link to comment Share on other sites More sharing options...
Grafica Posted August 10, 2012 Author Share Posted August 10, 2012 Oh, my bad. I don't have email set up with xampp. I uploaded it to the server, and it worked. Thanks, guys!!! A LOT! Now I need to code some security measures. Link to comment Share on other sites More sharing options...
Edward Posted August 10, 2012 Share Posted August 10, 2012 You will need to be on a live host to receive an email but there is also chance that Yahoo could blacklist it if server is unknown. Link to comment Share on other sites More sharing options...
Recommended Posts