• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Error: Special Characters Must Be Escaped

Community Beginner ,
Jul 10, 2020 Jul 10, 2020

Copy link to clipboard

Copied

Hello. I'm attempting to put php code (for the first time) in an html document. I'm getting a "Special Characters Must be Escaped" error at the opening and closing tags of the php code. I'll post all the code I'm using but the php code will eventually be placed in a separate document for the form element to action to. Any help would be greatly appreciated.

 

<!DOCTYPE HTML>
<html>
<body>
<form name="photosubmission form" action="photoform-to-email.php"
<form name="photosubmissionform" action="photoform-to-email.php>
<label for="fname">First Name:</label><br>
<input type="text" id="fname" name="fname" placeholder="John" required><br>
<label for="lname">Last Name:</label><br>
<input type="text" id="lname" name="lname" placeholder="Doe" required><br>
<label for="phone">Phone Number:</label><br>
<input type="tel" id="phone" name="phone" class="phone" placeholder="123.456.7890" pattern="[0-9]{3}.[0-9]{3}.[0-9]{4}"><br>
<label for="email">Email:</label><br>
<input type="email" id="email" name="email" class="email" placeholder="johndoe@gmail.com" required><br>
<label for="image">Image File</label><br>
<input type="file" id="image" name="image" multiple>
<input type="submit" value="Submit">
</form>
</body>
</html>

 

<?php
if(!isset{$_POST['submit']))
{
echo "Error! You need to submit the form!";
}

$fname = $_POST['fname'];
$lname = $_POST['lname'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$file = $_POST['file'];

if(empty($fname) || empty($lname))
{ echo "Please enter your full name.";
exit;
}

if(empty($email))
{ echo "Please enter a valid email address.";
exit;
}

$email_from = 'marketing@cittrucks.com';
$email_subject = "New Photo Contest Submission";
$email_body = "You have received a new submission from $name. \n".
"email address: $visitor_email\n".
"Here is the submission: \n $message".

$to = "marketing@cittrucks.com";
$headers = "From: $email_from \r\n";
mail($to,$email_subject,$email_body,$headers);


function IsInjected($str)
{
$injections = array('(\n+);,
'(\r+)',
'(\t+)',
'(%0A+)',
'(%08+)',
'(%09+)'
$inject = join('|', $injections);
$inject = "/$inject/i";

if(preg_match($inject,$str))
{return true;
}
else
{return false;
}

if(IsInjected($email))
{
echo "Please enter a valid email address.";
exit;
}
?>

TOPICS
Code , Error , How to

Views

674

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 13, 2020 Jul 13, 2020

DW's linter will show errors when you use php tags inside a file saved with the .html extension. It doesn't make a difference what you have selected in the bottom of the document window.

It uses a different error checker when the page is saved as .php and won't give the same error (the special characters must be escaped on all <?php> tags one). 

Votes

Translate

Translate
Community Beginner ,
Jul 10, 2020 Jul 10, 2020

Copy link to clipboard

Copied

I was in the process of editing lines 4 and 5 so please ignore those.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 10, 2020 Jul 10, 2020

Copy link to clipboard

Copied

Are you working with valid code inside a .php document?  See screenshot.

 

image.png

 

Nancy O'Shea— Product User, Community Expert & Moderator

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 13, 2020 Jul 13, 2020

Copy link to clipboard

Copied

LATEST

DW's linter will show errors when you use php tags inside a file saved with the .html extension. It doesn't make a difference what you have selected in the bottom of the document window.

It uses a different error checker when the page is saved as .php and won't give the same error (the special characters must be escaped on all <?php> tags one). 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines