我正在编写一个搜索引擎,我写了一个带有文本输入和按钮的表单:-<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条经验 获得超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 关注
- 79 浏览
添加回答
举报
0/150
提交
取消