我正在編寫一個搜索引擎,我寫了一個帶有文本輸入和按鈕的表單:-<form class="form-inline my-2 my-lg-0" action="" method="post" name="SearchEngine" enctype="multipart/form-data"> <div class="form-group"> <input class="form-control mr-sm-2" name="searchinput" type="search" placeholder="?????" aria-label="Search"> </div> <div class="form-group"> <button class="btn btn-outline-Dark my-2 my-sm-0" type="submit" style="direction:RTL;">????</button> </div> </form>后端 [ php 代碼 ]require_once '..\Config.php';$searchon = $_POST['searchinput'];$dbCon = "mysql:host=$host;dbname=$db_name";$PDOCon = new PDO($dbCon, $username, $password);$stmt = $PDOCon->prepare("SELECT * FROM items WHERE name='$searchon' OR chemicalcom= '$searchon'");$stmt->execute(); $rows = $stmt->fetchall();echo $rows['name'];問題是什么時候提交一個值到文本中沒有回音
1 回答

蠱毒傳說
TA貢獻1895條經(jīng)驗 獲得超3個贊
// to get the EXCEPTIONS
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
try{
$stmt = $dbh->prepare("SELECT * FROM items WHERE name=:name OR chemicalcom= :chemicalcom");
$stmt->bindParam(':name', $searchon);
$stmt->bindParam(':chemicalcom', $searchon);
$stmt->execute();
$rows = $stmt->fetchAll(); // not fetchall && fetchAll you will get an array so you need to loop over it to get the values like
foreach($rows as $r){
echo $r['name'];
}
} catch (PDOException $ex) {
echo $ex->getMessage();
}
- 1 回答
- 0 關(guān)注
- 97 瀏覽
添加回答
舉報
0/150
提交
取消