#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    21
    Rep 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>
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    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):
    PHP Code:
    echo 'No "escaping" necessary.'
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    119
    Rep Power
    33
    In lines 5 and 6 you are not only missing the ; but you are also missing the closing > on your input element. This works on my server:

    PHP Code:
    echo "First Name: <input type=\"text\" name=\"fname\" value=\"" .trim($_POST['fname'])."\">";
    echo 
    "Last Name: <input type=\"text\" name=\"lname\" value=\"" .trim($_POST['lname'])."\">"

    Comments on this post

    • ak4744710 agrees : thanks
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    21
    Rep Power
    0
    thought I was in php forum sorry about that and thank you to the other person works fine
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    21
    Rep Power
    0
    solved thanks for everyone's help
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    1
    Rep 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/

    Hope it will help somebody.

    -Neil

    Comments on this post

    • aeternus agrees : I would rather spend that money on some pint, try Netbeans it's free
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    677
    Rep Power
    7
    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.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    21
    Rep Power
    0
    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
  16. #9
  17. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    EclipsePDT is a free IDE that's designed specifically for PHP.
    HEY! YOU! Read the New User Guide and Forum Rules

    "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

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo