ak4744710 Posted February 11, 2013 Share Posted February 11, 2013 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> Quote Link to comment Share on other sites More sharing options...
cpd Posted February 11, 2013 Share Posted February 11, 2013 Needle in a haystack so post the error in future as well. In your function the "First name" and "Last name" lines don't end with a semicolon and moreover, you've not closed the input tag or string on either. Furthermore, using $_SERVER['PHP_SELF'] can come with some nasty consequences so don't use it like you have. Quote Link to comment Share on other sites More sharing options...
ak4744710 Posted February 11, 2013 Author Share Posted February 11, 2013 Parse error: syntax error, unexpected 'trim' (T_STRING), expecting ',' or ';' in C:\wamp\www\SelfSubmittingStickyForm.php on line 5 Quote Link to comment Share on other sites More sharing options...
ak4744710 Posted February 11, 2013 Author Share Posted February 11, 2013 solved thanks for everyone's help Quote Link to comment Share on other sites More sharing options...
Christian F. Posted February 11, 2013 Share Posted February 11, 2013 Here's a snippet for sanitizing PHP_SELF, for those instances where you want/need to use it: http://forums.phpfreaks.com/topic/266827-code-snippet-for-protection-against-php-self-injections-attacks/unread/ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.