0
我構建了一個獲取信息的表單,它可以很好地工作,但是我遇到了一個問題,URL最後沒有更改。無法僅顯示指向該搜索詞的鏈接。PDO搜索表單斷開的鏈接
說我搜索術語「谷歌搜索」
我的網址仍然是
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';
}
?>
有時我忘記了最簡單的事情,謝謝! – Bianca 2014-12-19 08:23:01
我改變了方法=「GET」我認爲它已經工作,但現在它顯示我所有的結果與我搜索的任何術語?任何建議 – Bianca 2014-12-19 08:50:07
聖誕節即將來臨^^!將'$ var1 = $ _POST ['var1'];'更改爲'$ var1 = $ _GET ['var1'];' – Robert 2014-12-19 09:02:44