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.

Recommended Answers

All 5 Replies

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

Member Avatar for rajarajan2017

Check for semicolons, proper closing braces, space between <? php, ? missing and all.

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

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.

<!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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.