I received this error when I run this code:
Parse error: syntax error, unexpected '$page_number' (T_VARIABLE) in C:\wamp\www\SearchEngine\search.php on line 5
Code for search.php:
<?php
//php code goes here
include 'connect.php'; // for database connection
$query = $_GET['q'] // query
$page_number = $_GET['page'];
?>
<html>
<head>
<title>
Brandon's Search Engine
</title>
<style type="text/css">
#search-result {
font-size: 17pt;
margin: 5px;
padding: 2px;
border-color: black;
}
#search-result:hover {
border-color: 1px solid red;
background-color: #cccccc;
}
#name {
color: #ff9999;
}
#name:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<form method="GET" action="search.php">
<table>
<tr>
<td>
<h2>
Brandon's Search Engine
</h2>
</td>
</tr>
<tr>
<td>
<input type="text" value="<?php echo htmlspecialchars($_GET['q']); ?>" name="q" size="80" name="q"/>
<input type="submit" value="Search" />
</td>
</tr>
<tr>
<td>
<?php
//SQL query
$stmt = "SELECT * FROM searchengine WHERE title LIKE '%" . mysqli_real_escape_string($con,$query) . "%' OR link LIKE '%" . mysqli_real_escape_string($con,$query) . "%' LIMIT $page_number, 10";
$result = mysqli_query($con,$stmt) or die(mysqli_error($con));
$number_of_result = mysqli_num_rows($result);
if ($number_of_result < 1) {
echo "Your search did not match any documents. Please try different keywords.";
} else {
//results found here and display them
$index = 0;
while (($row = \mysqli_fetch_assoc($result)) && ($index < 10)) {//10 results per page
$title = $row["title"];
$link = $row["link"];
echo "<div id='search-result'>";
echo "<div id='title'><a href='$link'>" . $title . "</a></div>";
echo "<br />";
echo "<div id='link'><small>" . $link . "</small></div>";
echo "</div>";
$index++;
}
}
?>
</td>
</tr>
<tr>
<td>
<input type="hidden" name="page" value="<?php echo $page_number+10";
</td>
</tr>
</table>
</form>
</body>
</html>
I believe there are still a lot of errors in this code.
Can someone please help me and explain to me so that I can understand and learn something too?
Please add ;
after $_GET['q']
And close the last php
tag
<td>
<input type="hidden" name="page" value="<?php echo $page_number+10; ?>" />
</td>