SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Denmark
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Parsing error: solution eludes me.

    Hi guys,

    Somewhere in this code:

    PHP Code:
    $dbname 'your databasename here...';
    $dbhost 'your databasehost here...';
    $dbusername 'your databaseusername here...';
    $dbpassword 'your database password here...';
    function 
    form($dbname,$dbhost,$dbusername,$dbpassword) {
    echo 
    "<form id='dblink_params' name='dblink_params' method='post' action='$_SERVER['PHP_SELF']'>
    <fieldset>
             <legend>1). YOUR DATABASE RELATED PARAMETERS:</legend>
                     <label>Database name:</label><input type='text' size='20' name='dbname' value='
    $dbname'/>\n
                     <label>Database hostname:</label><input type='text' size='20' name='dbhost' value='
    $dbhost'/><\n
                     <label>Database username:</label><input type='text' size='20' name='dbusername' value='
    $dbusername'/>\n
                     <label>Database password:</label><input type='password' size='20' name='dbpassword' value='
    $dbpassword'/>\n
              <span><input type='submit' value='submit' name='submit'></span>
             </fieldset>
    </form>"
    ;

    - something generates the following error:

    Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in...

    - and I cannot see what it is..

    What's going wrong here? As far as I can see, this is a dynamic form done the way it's supposed to.
    "There can be only one masterfarter"

  2. #2
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Denmark
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmmm I tried backslashing the "$" sign in $_SERVER['PHP_SELF'] out, and then the form displays. Why? How else am I supposed to do it?
    "There can be only one masterfarter"

  3. #3
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Any of these ways would be valid:

    PHP Code:
    echo "<form id='dblink_params' name='dblink_params' method='post' action='{$_SERVER['PHP_SELF']}'> ... 
    PHP Code:
    echo "<form id='dblink_params' name='dblink_params' method='post' action='" $_SERVER['PHP_SELF'] . "'> ... 

    PHP Code:
    //Omitting the single quotes outside a double-quoted string would be incorrect
    echo "<form id='dblink_params' name='dblink_params' method='post' action='$_SERVER[PHP_SELF]'> ... 
    See the PHP manual chapter on strings.

  4. #4
    SitePoint Evangelist
    Join Date
    Sep 2004
    Location
    Oregon
    Posts
    445
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dan corrected you.

    The problem is you have a ' inside of a '

    action='$_SERVER['PHP_SELF']'>

    So at the 'PHP, it thinks it is ending the action, so the HTML code is then action='$_SERVER[' and it is reading everything after that closing apostrophy as excess and thus unexpected text.

  5. #5
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Denmark
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah ok, thanks. I've jut gone from plain html forms in PHP to using dynamic forms and I guess it takes a little getting used to.

    I need to adjust the four other variables within the label tags to make the default text display in these four fields as well then.

    Thanks.
    "There can be only one masterfarter"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •