我有一個form
,人們可以在該數據庫中搜索某個用戶。當他們搜索用戶並點擊提交時,他們被重定向到不同的頁面並顯示結果。在html中顯示php結果
我唯一的問題是,結果被需要的html標籤之前顯示 - 這裏的頁面的樣子通過檢查元素的例子:
"Bobby123
"
<!DOCTYPE html>
<html>
<body>
</body>
</html>
如何顯示結果所需的HTML AFTER標籤?如何設置「設置位置」以顯示結果?
這裏是我的代碼:
<?php
if(isset($_POST['submit'])) {
$term = $_POST['search'];
$searchuser = $stmt = $con->prepare("SELECT * FROM users WHERE username LIKE :term");
$stmt->bindValue(':term', '%'.$term.'%');
$stmt->execute();
if($searchuser->rowCount() > 0) {
while($row = $searchuser->fetch()){
$name = $row['username'];
echo $name;
}
}else{
echo 'No results';
}
}
?>
<form method="post" action="results.php">
<input name="search" type="search">
<input type="submit" name="submit">
</form>
上results.php的代碼簡單地說就是:
<!DOCTYPE html>
<html>
<body>
</html>
如果可能的話,我不喜歡用編碼如Javascript,jQuery的,或任何在客戶端運行。
你是如何顯示的結果在結果.php沒有任何PHP代碼? –
不要回顯,存儲結果並將它們放在文檔中屬於的位置。 – chris85
@ raptor96'form'元素中的'action'標籤顯示結果results.php –