Syntax error

  You are currently not logged in. You can view the forums, but cannot post messages. Log In | Register

03-Feb-12 15:58
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 } ?>
07-Feb-12 23:22
@eman: You didn't close your top block of PHP code. Try this:


...
$gtr_shop1_products=$db->query($query); // $gtr_shop1_products contains the result set

?>

<?php foreach ($gtr_shop1_product as $gtr_shop1_product) { ?>
...


--
Matt Doyle, Elated
3rd Edition of my jQuery Mobile book out now! Learn to build mobile web apps. Free sample chapter: http://store.elated.com/

 
New posts
Old posts

Follow Elated