Hi,
I'm trying to write a script to retrieve search results from my database but it's not working. Every time I enter a search term, I get this parse error: parse
error, expecting `']'' in /Users/... on line 10. Changing the line to match the what it expected does nothing and I get the same parse error. Taking the line out also gave me the same parse error, still line 10. Here's the code, with line 10 in bold and italics:
<html>
<head>
<title>Search Results</title>
</head>
<body>
<h1>Search Results</h1>
<?php
// create short variable names
$searchtype=$_POST['searchtype'];
$searchterm=trim($_POST['searchterm']);
if (!$searchtype || !$searchterm) {
echo 'You have not entered search details. Please go back and try again.';
exit;
}
if (!get_magic_quotes_gpc()){
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
}
@ $db = new mysqli('localhost', 'root', 'yourpasswordhere', 'Enviroindex');
if (msqi_connect_errno()) {
echo 'Error: Could not connect to database. Please Try again later.';
exit;
}
$query = "select * from Enviroindex where ".$searchtype." like '%".$searchterm."%'";
$result = $db->($query);
$num_results = $result->num_rows;
echo "<p>Number of results found: ".$num_results."</p>";
for ($i=0; $i <$num_results; $i++) {
$row = $result->fetch_assoc();
echo "<p><strong>".($i+1).". Organization Name: ";
echo htmlspecialchars(stripslashes($row['organizationname']));
echo "</>strong><br />Username: ";
echo stripslahes($row['username']);
echo "<br />Organization Type: ";
echo stripslashes($row['organizationtype']);
echo "</p>";
}
$result->free();
$db->close();
?>
</body>
</html>
Any help would be appreciated.
(Added [noparse]
[/noparse] tags around code ~ NogDog)[/i]