Skip navigation
Reynold Dreamweaver CS6
Currently Being Moderated

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting ']' in /home/phpzendr/pub

Nov 12, 2012 4:34 AM

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting ']' in /home/phpzendr/public_html/Attendance.php on line 64

 

How can I use Balance brace to identify with this parse error?

Balance Braces.png

 

The article was not clear how to use this functionality. Please advice. I have the above error message.

 
Replies
  • Currently Being Moderated
    Nov 12, 2012 4:39 AM   in reply to Reynold Dreamweaver CS6

    I don't think balance braces is going to be the right tool to use for this, simply because your visual scan of the code would be so much more effective.  Try this -

     

    1.  Do a source code search of the current document to look for "[".

    2.  For each location found, visually inspect the code to make sure that there is a required closing "]".

     

    You should find it in a hurry.

     

    Balance braces only "balances" the innermost set of 'braces' starting from the cursor insertion point.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 12, 2012 5:01 AM   in reply to Reynold Dreamweaver CS6

    You could always use regular expressions to search the entire page for all instances of "[" that are NOT followed by "]", but you'd have to be very crafty with regular expressions to formulate that search expression - I am not.

     

    My approach would be to use DW's Find and Replace tool to find all "[" in the current document. This will generate a list of hits in the search log. Double click each entry and visually inspect the code at that location to find the element that is improperly terminated.

     

    My actual approach would be just to visually scan down the page to see where the error is, but if your eye is not accustomed to looking at this kind of code, it may be easier to use the Search tool.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 12, 2012 5:22 AM   in reply to Reynold Dreamweaver CS6

    Are you sure that is the correct page?  There are 44 instances of "[" and 44 instances of "]" so I don't see a missing one. Does the error message give a line #?

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 12, 2012 5:26 AM   in reply to MurraySummers

    Also it's a little puzzling why you have two instances of the insertion code on the page, although the second instance will never be executed.

     

    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {

      $insertSQL = sprintf("INSERT INTO attendlist (Windowsid, title, firstname, surname, extension, mobile, jobrole, course, cpg, mgrname, room, Adate) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",

                           GetSQLValueString($_POST['Wid'], "text"),

                           GetSQLValueString($_POST['title'], "text"),

                           GetSQLValueString($_POST['firstname'], "text"),

                           GetSQLValueString($_POST['surname'], "text"),

                           GetSQLValueString($_POST['contactno'], "text"),

                           GetSQLValueString($_POST['mobile'], "text"),

                           GetSQLValueString($_POST['jobrole'], "text"),

                           GetSQLValueString($_POST['courses'], "text"),

                           GetSQLValueString($_POST['cpg2'], "text"),

                           GetSQLValueString($_POST['mgrname2'], "text"),

                           GetSQLValueString($_POST['troom'], "text"),

                           GetSQLValueString($_POST['Adate2'], "date"));

     

     

      mysql_select_db($database_attending, $attending);

      $Result1 = mysql_query($insertSQL, $attending) or die(mysql_error());

     

     

      $insertGoTo = "Listing.php";

      if (isset($_SERVER['QUERY_STRING'])) {

        $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";

        $insertGoTo .= $_SERVER['QUERY_STRING'];

      }

      header(sprintf("Location: %s", $insertGoTo));

    }

     

     

    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {

      $insertSQL = sprintf("INSERT INTO attendlist (title, firstname, surname, extension, mobile, jobrole, course, cpg, mgrname, room, Adate) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",

                           GetSQLValueString($_POST['title'], "text"),

                           GetSQLValueString($_POST['firstname'], "text"),

                           GetSQLValueString($_POST['surname'], "text"),

                           GetSQLValueString($_POST['contactno'], "text"),

                           GetSQLValueString($_POST['mobile'], "text"),

                           GetSQLValueString($_POST['jobrole'], "text"),

                           GetSQLValueString($_POST['courses'], "text"),

                           GetSQLValueString($_POST['cpg2'], "text"),

                           GetSQLValueString($_POST['mgrname2'], "text"),

                           GetSQLValueString($_POST['troom'], "text"),

                           GetSQLValueString($_POST['Adate2'], "date"));

     

     

      mysql_select_db($database_attending, $attending);

      $Result1 = mysql_query($insertSQL, $attending) or die(mysql_error());

     

     

      $insertGoTo = "Listing.php";

      if (isset($_SERVER['QUERY_STRING'])) {

        $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";

        $insertGoTo .= $_SERVER['QUERY_STRING'];

      }

      header(sprintf("Location: %s", $insertGoTo));

     

    Finally, you are inserting data into the database without sanitizing it properly to prevent SQL injection - are you sure you want to do this?

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 12, 2012 5:54 AM   in reply to Reynold Dreamweaver CS6

    I just don't see anything on this page that would cause that error to be thrown.  Do you see the error message as soon as the page loads, or only after submitting the form?  Is the test data actually inserted into the database?

     

    By the way, to read about sanitizing user input, Google "php sanitize sql injection".  There are several good links there.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 12, 2012 8:26 AM   in reply to Reynold Dreamweaver CS6

    Before submit?  So as soon as you load the page you get the error?

     

    Here is your page - http://www.gws-sandbox.com/test-parse.php

     

    I have commented out the include link to the connection file at the top, the database selection block lines 37-41, and the free result block at the bottom below the </html>, in other words, only that code dealing with connecting to the database and fetching the results.  As far as I can tell this modified page does not throw an error when it loads (you can't submit anything though or you will get errors reflecting the missing database connection).

     

    So, unless I am mistaken and the error is in some of the code I have commented out, this means that the error would have to be in your connection file that is included at line 1 of the page.  How many lines of code are in that file (Connections/attending.php)?

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 13, 2012 4:30 AM   in reply to Reynold Dreamweaver CS6

    At Line 1, I have changed the code to <?php require_once('../Connections/attendance.php'); ?>.

     

    Wait - that cured your error?  So in your site, the attendance page is one folder level below the root folder?  That would certainly suggest that your site definition is bad, and it places all your other links under suspicion.  Anyhow, the parse error message you were getting would certainly NOT suggest to me that the problem was that the include file could not be found. Are you sure about this?

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 13, 2012 6:33 AM   in reply to Reynold Dreamweaver CS6

    Clearly you need to resolve your pathing/site definition problems first.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 13, 2012 8:14 AM   in reply to Reynold Dreamweaver CS6

    Often a site will have a remote root folder like

     

    public_html

     

    Does yours?

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 13, 2012 12:11 PM   in reply to Reynold Dreamweaver CS6

    You should NEVER have that folder in your local site.  Everything that is inside it will be improperly linked when you upload it.

     

    Your local root folder appears to be properly pathed from your site definition image.  That folder should *not* contain a public_html folder.  It should probably contain a SpryAssets folder, a TSScript folder and a Connections folder, along with the rest of your local files.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 13, 2012 2:53 PM   in reply to Reynold Dreamweaver CS6

    In your Remote site definition, public_html must be in the Root Directory field, just above the Web URL field.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 14, 2012 5:26 AM   in reply to Reynold Dreamweaver CS6

    You should be good to go.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points