Results 1 to 3 of 3

Thread: Syntax Error

  1. #1
    Join Date
    May 2007
    Posts
    66
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Syntax Error

    I keep getting this syntax error whenever I run this script below. Can anyone tell me how to correct this? I left the username and password empty for security. Thanks

    Parse error: syntax error, unexpected '<' in G:\Inetpub\wwwroot\LocalUser\eijenkins\WEB225\guitar_list.php on line 51

    http://198.86.244.3/eijenkins/web225/guitar_list.php

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Product Listing: Guitars</title>
    </head>

    <body>

    <?php

    $db_host = "localhost";
    $db_username = "x";
    $db_pass = "x";

    //Make the connection:
    @mysqli_connect ("$db_host", "$db_username","$db_pass") OR die ("Could not connect to MySQL");


    echo"<h1>Product Listing: Guitars</h1>";

    try {
    // statements that might throw an exception
    } catch (ExceptionClass $exception_name) {
    // statements that handle the exception
    }

    try {
    $db = new PDO($dsn, $username, $password);
    echo '<p>You are connected to the database!</p>';
    } catch (PDOException $e) {
    $error_message = $e->getMessage();
    echo "<p>An error occurred while connecting to
    the database: $error_message </p>";
    }

    try {
    // statements that might throw an exception
    } catch (Exception $e) {
    $error_message = $e->getMessage ();
    echo "<p>Error message: $error_message </p>";
    }

    $query = 'SELECT productID, productCode, productName, listPrice
    FROM gtr_shop1_products
    WHERE categoryID = 1';
    $gtr_shop1_products=$db->query($query); // $gtr_shop1_products contains the result set


    <?php foreach ($gtr_shop1_product as $gtr_shop1_product) { ?>
    <tr>
    <td><?php echo $gtr_shop1_product['productID']; ?></td>
    <td><?php echo $gtr_shop1_product['productCode']; ?></td>
    <td><?php echo $gtr_shop1_product['productName']; ?></td>
    <td><?php echo $gtr_shop1_product['listPrice']; ?></td>
    </tr>
    <?php } ?>

  2. #2
    Join Date
    Jul 2010
    Location
    Minnesota
    Posts
    256
    Thanks
    1
    Thanked 21 Times in 21 Posts

    Default

    Get rid of the <?php before the foreach loop

  3. #3
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    your third try/catch block is useless - there's no code inside the try{}.

    also,
    Please use the forum's bbcode tags and indent your code to make it more readable:

    for php code............[php] <?php /* code goes here */ ?> [/php]
    for html...............[html] <!-- markup goes here -->.....[/html]
    for js/css/other.......[code] code goes here................[/code]

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
  •