猿问

MySQL 中的 PHP 变量 [选择或] 语句未执行

我正在编写一个搜索引擎,我写了一个带有文本输入和按钮的表单:-


<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'];


问题是什么时候提交一个值到文本中没有回音


哆啦的时光机
浏览 80回答 1
1回答

蛊毒传说

// to get the EXCEPTIONS$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);try{&nbsp; $stmt = $dbh->prepare("SELECT * FROM items WHERE name=:name OR chemicalcom= :chemicalcom");$stmt->bindParam(':name', $searchon);$stmt->bindParam(':chemicalcom', $searchon);$stmt->execute();&nbsp;$rows = $stmt->fetchAll(); // not fetchall && fetchAll you will get an array so you need to loop over it to get the values like&nbsp; &nbsp;foreach($rows as $r){&nbsp; &nbsp; &nbsp;echo $r['name'];&nbsp; &nbsp; }&nbsp;} catch (PDOException $ex) {&nbsp; &nbsp; echo&nbsp; $ex->getMessage();&nbsp; }
随时随地看视频慕课网APP
我要回答