943,104 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 378
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Feb 8th, 2010
0

PHP form

Expand Post »
Just trying to get a very simple form working
Getting a
Parse error: syntax error, unexpected T_IS_EQUAL on line 10

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. $to = "";
  3. $subject = "Contact Us";
  4. $name = $_REQUEST['name'] ;
  5. $email = $_REQUEST['email'] ;
  6. $message = $_REQUEST['message'] ;
  7. $headers = "From: $email";
  8. $embody = "Name: $name\nEmail: $email\nSuggestion: $message" ;
  9. $sent = mail($to, $subject, $embody, $headers) ;
  10. if($name || $email || $message) == "" {
  11. echo "You seem to have left something out. Please fill in all the fields and try again.<br /><br /><a href=\"javascript:closeWindow();\">Close</a>"; }
  12. else
  13. if($sent)
  14. {echo "Thank you $name, your mail has been sent successfully with the message of:<br /><br /><i>$message</i><br /><br /><a href=\"javascript:closeWindow();\">Close</a>"; }
  15. else
  16. {echo "We encountered an error sending your mail<br /><br /><a href=\"javascript:closeWindow();\">Close</a>"; }
  17. ?>

I know its something with the checking if the fields are blank, but I can't find what
Thanks
Last edited by Mouse1989; Feb 8th, 2010 at 8:28 am.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Mouse1989 is offline Offline
12 posts
since Apr 2009
Feb 8th, 2010
0
Re: PHP form
Click to Expand / Collapse  Quote originally posted by Mouse1989 ...
Just trying to get a very simple form working
Getting a
Parse error: syntax error, unexpected T_IS_EQUAL on line 10

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. $to = "";
  3. $subject = "Contact Us";
  4. $name = $_REQUEST['name'] ;
  5. $email = $_REQUEST['email'] ;
  6. $message = $_REQUEST['message'] ;
  7. $headers = "From: $email";
  8. $embody = "Name: $name\nEmail: $email\nSuggestion: $message" ;
  9. $sent = mail($to, $subject, $embody, $headers) ;
  10. if($name || $email || $message) == "" {
  11. echo "You seem to have left something out. Please fill in all the fields and try again.<br /><br /><a href=\"javascript:closeWindow();\">Close</a>"; }
  12. else
  13. if($sent)
  14. {echo "Thank you $name, your mail has been sent successfully with the message of:<br /><br /><i>$message</i><br /><br /><a href=\"javascript:closeWindow();\">Close</a>"; }
  15. else
  16. {echo "We encountered an error sending your mail<br /><br /><a href=\"javascript:closeWindow();\">Close</a>"; }
  17. ?>

I know its something with the checking if the fields are blank, but I can't find what
Thanks
In the above code you forgot to put

braces for the if statement, try the following

if(($name || $email || $message) == "")


Thanks & Regards
Sai Prem
<snipped>
Last edited by nav33n; Feb 8th, 2010 at 9:46 am. Reason: Fake signature snipped. Use Control Panel -> Edit Signature to add a signature.
Reputation Points: 16
Solved Threads: 28
Posting Whiz in Training
saiprem is offline Offline
209 posts
since Feb 2010
Feb 8th, 2010
0
Re: PHP form
Quote ...
In the above code you forgot to put

braces for the if statement, try the following

if(($name || $email || $message) == "")
That fixed the error, but now I am getting the "You seem to have left something out. P..." all the time even when everything is filled in.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Mouse1989 is offline Offline
12 posts
since Apr 2009
Feb 8th, 2010
0
Re: PHP form
If you are doing it from local environment, the mail sending will not works for you. You need to set the smtp address and port number in the php.ini file
Last edited by saiprem; Feb 8th, 2010 at 9:51 am. Reason: Fake signature snipped.
Reputation Points: 16
Solved Threads: 28
Posting Whiz in Training
saiprem is offline Offline
209 posts
since Feb 2010
Feb 8th, 2010
0
Re: PHP form
It all works fine and I get the form mail through to my email inbox. Everything is ok, I just wish to check the boxes are not blank
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Mouse1989 is offline Offline
12 posts
since Apr 2009
Feb 8th, 2010
0
Re: PHP form
Try changing if($name || $email || $message) == "" to if(empty($name)||empty($mail)||empty($message)) { }
The preferred method of checking whether or not a variable is empty is with the empty() function ( bool empty ( mixed $var ) ).
The OR operator (||) doesn't work quite the way you used it above.
You also left out a closing bracket.
Last edited by Jerail; Feb 8th, 2010 at 10:11 am.
Reputation Points: 11
Solved Threads: 5
Light Poster
Jerail is offline Offline
39 posts
since Feb 2010
Feb 8th, 2010
0
Re: PHP form
PHP Syntax (Toggle Plain Text)
  1. <form method="post" action="contact.php" onsubmit="window.open('contact.php','popup','width=200,height=200,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0'); return false">
  2. Name: <input name="name" type="text" maxlength="15" value="">
  3. <br />
  4. Email:&nbsp;&nbsp;<input name="email" type="text" maxlength="50" value="">
  5. <br />
  6. Suggestion:<br />
  7. <textarea name="message" rows="5" cols="40" value=""></textarea>
  8. <br>
  9. <input type="submit" value="Submit"><input type="reset" value="Reset">
  10. </form>

PHP Syntax (Toggle Plain Text)
  1. $to = "email ommitted";
  2. $subject = "Contact Us";
  3. $name = $_REQUEST['name'] ;
  4. $email = $_REQUEST['email'] ;
  5. $message = $_REQUEST['message'] ;
  6. $headers = "From: $email";
  7. $embody = "Name: $name\nEmail: $email\nSuggestion: $message" ;
  8. $sent = mail($to, $subject, $embody, $headers) ;
  9. if(empty($name)||empty($mail)||empty($message)) {
  10. echo "You seem to have left something out. Please fill in all the fields and try again.<br /><br /><a href=\"javascript:closeWindow();\">Close</a>"; }
  11. else
  12. if($sent)
  13. {echo "Thank you $name, your mail has been sent successfully with the message of:<br /><br /><i>$message</i><br /><br /><a href=\"javascript:closeWindow();\">Close</a>"; }
  14. else
  15. {echo "We encountered an error sending your mail<br /><br /><a href=\"javascript:closeWindow();\">Close</a>"; }
  16. ?>

Still same problem :/ get blank error even when all boxes are filled, forgot to add the HTML form before. Possible conflict with value=""?
Last edited by Mouse1989; Feb 8th, 2010 at 10:25 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Mouse1989 is offline Offline
12 posts
since Apr 2009
Feb 8th, 2010
0
Re: PHP form
Yes you should not use value="" in your source, and more over the default will be null, it is not necessary to put that, remove that and retry again
Reputation Points: 16
Solved Threads: 28
Posting Whiz in Training
saiprem is offline Offline
209 posts
since Feb 2010
Feb 8th, 2010
0
Re: PHP form
Change empty($mail) to empty($email)
There's a discrepancy between your variables. $mail does not exist.
Also, you should really do your validation before sending the e-mail with mail(). This would avoid a lot of unnecessary blank e-mails being sent.

Also, do what saiprem said and remove the value = "" attributes from your HTML form. value isn't even a valid attribute of <textarea> .
Last edited by Jerail; Feb 8th, 2010 at 10:33 am.
Reputation Points: 11
Solved Threads: 5
Light Poster
Jerail is offline Offline
39 posts
since Feb 2010
Feb 8th, 2010
0
Re: PHP form
Thanks for the discrepancy note

How would I go about doing validation beforehand?
Last edited by Mouse1989; Feb 8th, 2010 at 11:23 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Mouse1989 is offline Offline
12 posts
since Apr 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: switch case function
Next Thread in PHP Forum Timeline: plz help to display multidimensional array in html table





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC