Syntax Error which won't go away

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
halbarad
Forum Newbie
Posts: 5
Joined: Tue Jan 22, 2008 7:51 am

Syntax Error which won't go away

Post by halbarad »

Hi

I am working on having a form on a web page for submitting queries to an email address. I know this isn't exactly a good idea so I am working on checking the text area to see if there is any special characters (html tags opening, attempts to close php tags or quotes) however the two methods I have come up with to do so are failling.

My first attempt was to loop through the inputted string and check each character to see if it was a "<" tag but I kept getting a syntax error saying
Parse error: syntax error, unexpected $end in File goes here on line 59
Then I realised that this method could be very time consuming for longer queries so I decided to browse around to see other methods and came across regex which seemed much simpler to use with preg_match. So I made a short regex which would check the query had only characters from a small list of characters that I wanted to allow and would then return a message if it had even one unallowed character.

When I tested this method I got exactly the same message (with a different line) as before. I have checked the line it refers to and all that's there is the end php tag and the line before closes an if statement.

This is the code I used for the regex one as it seems the most versatile:

Code: Select all

<?php
$comment = $_POST['contact_query'];
$sender = $_POST['contact_name'];
$email = $_POST['contact_email'];
$phone = $_POST['contact_phone'];
$header = "From: ".$sender;
$to = ("email address");
$subject = ("Query from website");
 
$sendMail = false;
$mask = "[^\w\s.!?,]";
$charCheck = preg_match($mask, $comment);
 
if ($charCheck == 0)
{
    echo "You cannot submit a query containing special characters. Please go back and try again";
}
else
{
    $sendmail = true;
}
 
if ($sendMail == true)
{
    $body = <<< MAIL
 
    $comment
    Senders Name: $sender
    Senders Email: $email
    Senders Contact: $phone
 
    MAIL;
 
 
    if(mail($to, $subject, $body, $header))
    {
        header( 'Location: link to page') ;
    }
    else
    {
        echo "A Problem Occurred, Please Go Back and Try Again";
    }
}
?>
Can anyone help find out what's wrong with this? I can't seem to locate the source of the error.

Also, if there is any other problems with my coding can you point it out to me please.

Your help is greatly appreciated.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Syntax Error which won't go away

Post by VladSun »

There must be no white spaces before MAIL;
There are 10 types of people in this world, those who understand binary and those who don't
halbarad
Forum Newbie
Posts: 5
Joined: Tue Jan 22, 2008 7:51 am

Re: Syntax Error which won't go away

Post by halbarad »

VladSun wrote:There must be no white spaces before MAIL;
Thanks, I'm sure that's worked other times when I have used that as it's pretty much just copied from a previous page I wrote where it worked.

I'm still getting the error message as well, just in case that was supposed to fix it (and if it did I would be kicking myself now).
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Syntax Error which won't go away

Post by VladSun »

I'm pretty sure that's the reason for this error message. It must be:

Code: Select all

 
     $body = <<< MAIL
  
     $comment
     Senders Name: $sender
     Senders Email: $email
     Senders Contact: $phone
  
MAIL;
 
There are 10 types of people in this world, those who understand binary and those who don't
halbarad
Forum Newbie
Posts: 5
Joined: Tue Jan 22, 2008 7:51 am

Re: Syntax Error which won't go away

Post by halbarad »

I thought you meant before the first MAIL. I tried that and it has fixed it.

Thanks a lot.
Post Reply