0
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/a1420653/public_html/processform.php on line 46

Here is the code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php

// include MySQL-processing classes

require_once 'mysql.php';

try{

// connect to MySQL

$db=new MySQL(array
('host'=>'xxx.webhost.com','user'=>'admin','password'=>'admin',
'database'=>'search'));

$searchterm=$db->escapeString($_GET['searchterm']);

$result=$db->query("SELECT ProductList FROM
products WHERE MATCH(ProductList) AGAINST
('$searchterm')");

if(!$result->countRows()){

echo '<div class="maincontainer"><h2>No results were found. Go
back and try a new search.</h2></div>'."n";

}

else{

// display search results

echo '<div class="maincontainer"><h2>Your search criteria
returned '.$result->countRows().' results.</h2>'."n";

while($row=$result->fetchRow()){

echo '<div class="rowcontainer"><p><strong>CD Player:</strong>'.$row['cd player'].'</p>;
<p><strong>Chocolate:</strong>'.$row['chocolate'].'</p>;
<p><strong>Tea:</strong>'.$row['tea'].'</p></div>'."n";

}

{

echo '</div>';

}

}

catch(Exception $e){

echo $e->getMessage();

exit();

}

?>
</body>
</html>

I've tried to find out the problem for the past 1 hour. Can anyone find out the bug?
Thanks.

Edited by mike_2000_17: Fixed formatting

4
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by silviuks
0

Hi LalinM,

Running this I get:

Parse error: syntax error, unexpected T_CATCH in /Users/james/Desktop/untitled.php on line 59

Removing the random { in the following code seems to get it working.

{

echo '</div>';

Hope that helps,

James

0

You did not close the try "}" (just before catch)

Edited by silviuks: n/a

0

Hi LalinM,

Running this I get:

Removing the random { in the following code seems to get it working.

{

echo '</div>';

Hope that helps,

James

Hi James,

Thanks for your reply. I removed the { but I get the same result.

Re: silviuks, thanks for your answer but the way I see it I have closed the try {. Can you please tell me exactly where the fault is? I can't seem to find it.

Edited by LalinM: n/a

0
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php

// include MySQL-processing classes

require_once 'mysql.php';

try{

// connect to MySQL

$db=new MySQL(array
('host'=>'xxx.webhost.com','user'=>'admin','password'=>'admin',
'database'=>'search'));

$searchterm=$db->escapeString($_GET['searchterm']);

$result=$db->query("SELECT ProductList FROM
products WHERE MATCH(ProductList) AGAINST
('$searchterm')");

if(!$result->countRows()){

echo '<div class="maincontainer"><h2>No results were found. Go
back and try a new search.</h2></div>'."n";

}

else{

// display search results

echo '<div class="maincontainer"><h2>Your search criteria
returned '.$result->countRows().' results.</h2>'."n";

while($row=$result->fetchRow()){

echo '<div class="rowcontainer"><p><strong>CD Player:</strong>'.$row['cd player'].'</p>;
<p><strong>Chocolate:</strong>'.$row['chocolate'].'</p>;
<p><strong>Tea:</strong>'.$row['tea'].'</p></div>'."n";

}

{

echo '</div>';

}

}

catch(Exception $e){

echo $e->getMessage();

exit();

}

?>
</body>
</html>

The } from line 55 closes the { from line 51. } from 57 closes the else and "try {" is hanging up.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.