herrpoon
December 11th, 2005, 02:23 PM
Hi, was looking at php and mysql for the first time today and I'm having a bit of a problem. From this ebook I've got, I've already entered some data into a mysql database and now I'm trying to get this damn search to work and for it to query the database and display the results as results.php.
Anyway I'm getting the following error: Parse error: parse error, unexpected '>' in /var/www/books/results.php on line 44. I've looked and looked and can't seem to find the problem. Below is the results.php where the problem must be!
<html>
<head>
<title> Book Search Results
</head>
<body>
<h1> Book Search Results</h1>
<?php
// create short variable names
$searchtype=$_POST['searchtype'];
$searchterm=$_POST['searchterm'];
$searchterm= trim($searchterm);
if (!$searchtype || !$searchterm)
{
echo 'You have not entered any search details. Please go back and try again.';
exit;
}
if (!get_magic_quotes_gpc())
{
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
}
@ $db = mysqli_connect('10.0.0.1', 'name', 'pword', 'database');
if (mysqli_connect_errno())
{
echo 'Error: Could not connect to database. Please try agian later.';
exit;
}
$query = "select * from books where ".$searchtype." like '%".$seachterm."%'";
$result = $db->query($query);
$num_results = $result->num_rows;
echo '<p>Number of books found: '.$num_results.'</p>;
for ($i=0; $i <$num_results; $i++)
{
$row = $result->fetch_assoc();
echo '<strong>'.($i+1).'. Title: ';
echo htmlspecialchars(stripslashes($row['title']));
echo '</strong><br />Author: ';
echo stripslashes($row['author']);
echo '<br />ISBN ' ;
echo stripslashes($row['isbn']);
echo '<br />Price: ';
echo stripslashes($row['price']);
echo '</p>' ;
}
$result->free();
$db->close();
?>
</body>
</html>
Any help would be very much appreciated :)
P.s Line 44 is "echo '<strong>'.($i+1).'. Title: ';"
Anyway I'm getting the following error: Parse error: parse error, unexpected '>' in /var/www/books/results.php on line 44. I've looked and looked and can't seem to find the problem. Below is the results.php where the problem must be!
<html>
<head>
<title> Book Search Results
</head>
<body>
<h1> Book Search Results</h1>
<?php
// create short variable names
$searchtype=$_POST['searchtype'];
$searchterm=$_POST['searchterm'];
$searchterm= trim($searchterm);
if (!$searchtype || !$searchterm)
{
echo 'You have not entered any search details. Please go back and try again.';
exit;
}
if (!get_magic_quotes_gpc())
{
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
}
@ $db = mysqli_connect('10.0.0.1', 'name', 'pword', 'database');
if (mysqli_connect_errno())
{
echo 'Error: Could not connect to database. Please try agian later.';
exit;
}
$query = "select * from books where ".$searchtype." like '%".$seachterm."%'";
$result = $db->query($query);
$num_results = $result->num_rows;
echo '<p>Number of books found: '.$num_results.'</p>;
for ($i=0; $i <$num_results; $i++)
{
$row = $result->fetch_assoc();
echo '<strong>'.($i+1).'. Title: ';
echo htmlspecialchars(stripslashes($row['title']));
echo '</strong><br />Author: ';
echo stripslashes($row['author']);
echo '<br />ISBN ' ;
echo stripslashes($row['isbn']);
echo '<br />Price: ';
echo stripslashes($row['price']);
echo '</p>' ;
}
$result->free();
$db->close();
?>
</body>
</html>
Any help would be very much appreciated :)
P.s Line 44 is "echo '<strong>'.($i+1).'. Title: ';"