I built a form that fetches information it works great but there's a problem I came across, the URL isn't changing at the end. Making it impossible to display a link to that search term only.
Say I searched for the term "Google Search"
My URL is still
http://localhost/search.php
When I worked with mysql after I've searched a term it would look some what like this
http://localhost/search.php?k=google+search
What do I change to make this possible?
search engine form:
<form name="frmSearch" method="post" action="../search.php">
<input class="inp" name="var1" type="text" id="var1">
<input class="btn" type="submit" value="Search">
</form>
Search engine page:
<?php
$nameofdb = 'xxxxxx';
$dbusername = 'xxxxxx';
$dbpassword = 'xxxxxx';
// Connect to MySQL via PDO
try {
$dbh = new PDO("mysql:dbname=$nameofdb;host=xxxxxx", $dbusername, $dbpassword);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
$var1 = $_POST['var1'];
$query = "SELECT * FROM pages WHERE title LIKE :search OR keywords LIKE :search";
$stmt = $dbh->prepare($query);
$stmt->bindValue(':search', '%' . $var1 . '%', PDO::PARAM_INT);
$stmt->execute();
/* Fetch all of the remaining rows in the result set
print("Fetch all of the remaining rows in the result set:
"); */
$result = $stmt->fetchAll();
foreach( $result as $row ) {
/* echo */ $row["title"];
/* echo */ $row["keywords"];
/* echo */ $row["photo"];
/* echo */ $row["link"];
echo "<a href=$row[link]> $row[photo] </a>";
}
if ($stmt->rowCount() > 0) {
$result = $stmt->fetchAll();
foreach( $result as $row ) {
echo $row["id"];
echo $row["title"];
}
} else {
echo 'There is nothing to show';
}
?>