Jump to content

Can you Find my syntax error expecting ',' or ';' please


ak4744710

Recommended Posts

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.