Can you Find my syntax error expecting ',' or ';' please
Discuss Can you Find my syntax error expecting ',' or ';' please in the PHP Development forum on Dev Shed. Can you Find my syntax error expecting ',' or ';' please PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
Posts: 21
Time spent in forums: 3 h 5 m 44 sec
Reputation Power: 0
Can you Find my syntax error expecting ',' or ';' please
This is driving me crazy trying to figure out what I am doing wrong with this form I am guessing something is not closing correctly but i have no clue what I have submitted my code below if anyone can please help! Also before anyone says I am forgeting the closing tags on 5 and 6 test it and see it will not work even with the semi coluns thats what has me so stumped.
<?php
function printForm($strMessage){
echo "<strong>" .$strMessage."</strong>";
echo "<form method=\"post\" action=\"" .$_SERVER['PHP_SELF']. "\" name=\"form\">\n";
echo "First Name: <input type=\"text\" name=\"fname\" value=\"" .trim($_POST['fname'])."\"
echo "Last Name: <input type=\"text\" name=\"lname\" value=\"" .trim($_POST['lname'])."\"
echo "<input type=\submit\" value=\"send\" name=\"submit\"/>\n";
echo "</form>\n";
}
?>
<html>
<head>
<title>Self Submitting Sticky Form</title>
</head>
<body>
<?php
if(isset($_POST['submit'])){
$firstname=trim($_POST['fname']);
$lastname=trim($_POST['lname']);
if ($firstname==''){
$strMessage='Please enter your first name.';
printForm($strMessage);
}
elseif ($lastname==''){
$strMessage='Please enter your last name.';
printForm($strMessage);
}
else{
$strMessage='Thank you. your information was sent.';
echo $strMessage;
}
}
else{
$strMessage='Please enter all fields below:';
printForm($strMessage);
}
?>
</body>
</html>
Posts: 1,845
Time spent in forums: 1 Month 2 Weeks 1 Day 8 h 37 m 27 sec
Reputation Power: 813
C'mon, you know where the PHP forum is, and you should have realized that there's a code highlighter in the forum. Use it. It will actually tell you where the problem is.
Hint: Check those bits at the end of the line:
PHP Code:
"\"
That's not a complete string, because the closing quote is escaped.
By the way, you can avoid all this escaping by simply wrapping double quotes in a single quoted string (and vice versa):
Posts: 1
Time spent in forums: 28 m 35 sec
Reputation Power: 0
One of the easier ways to identify bugs is to use a good code editor. I paste your code in Dreamweaver CS6 and it shows me instantly where you did mistake - very easy.
As you've already solved the issue you know the bug was the wrong use of "quotation mark". You can't use double quote within double quote directly. PHP has some predefined rules. There is also trick to use double quote within double too. You can learn how to use different quotes and few tips here - schoolsofweb.com/php-strings/
Posts: 294
Time spent in forums: 3 Days 8 h 6 m 9 sec
Reputation Power: 5
Excellent note to pass on, especially to knew coders. Find yourself excellent code editor software you would be comfortable working with. I recommend PSPad to many. A friend of mine has had goode like with Notepad++. And many use Adobe's Create Suites (CS) lines.
Posts: 21
Time spent in forums: 3 h 5 m 44 sec
Reputation Power: 0
Quote:
Originally Posted by Triple_Nothing
Excellent note to pass on, especially to knew coders. Find yourself excellent code editor software you would be comfortable working with. I recommend PSPad to many. A friend of mine has had goode like with Notepad++. And many use Adobe's Create Suites (CS) lines.
I'm going to have to check those out i always use text pad
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002