我构建了一个获取信息的表单,但是我遇到了一个问题,最后URL没有变化。无法仅显示指向该搜索字词的链接。
说我搜索了“Google搜索”一词
我的网址仍然是
http://localhost/search.php
当我搜索一个术语后,当我使用mysql时,它会看起来像这样的
http://localhost/search.php?k=google+search
我可以做些什么来改变这种状况?
搜索引擎表单:
<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>
搜索引擎页面:
<?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:\n"); */
$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';
}
?>
答案 0 :(得分:0)
由于您正在使用&#34; POST&#34; -method进行请求,因此所有表单数据都会添加到HTTP正文中。
尝试使用method="GET"
这是一个简短的文档:HTML form method Attribute