Php PDO准备的语句和类似SQL的多个值
我有一个搜索表单,用户可以在其中搜索产品的序列号或名称 这是我的密码:Php PDO准备的语句和类似SQL的多个值,php,sql,pdo,prepared-statement,parameterized,Php,Sql,Pdo,Prepared Statement,Parameterized,我有一个搜索表单,用户可以在其中搜索产品的序列号或名称 这是我的密码: <?php require_once "pdo_rothConn.php"; if (isset($_POST['searchText'])){ $sql = "SELECT m_ipdb, m_name FROM machine WHERE 'm_ipdb' LIKE :number OR 'm_name' LIKE :name"; $stmt = $dbh->prepare($sql); $stmet-&
<?php
require_once "pdo_rothConn.php";
if (isset($_POST['searchText'])){
$sql = "SELECT m_ipdb, m_name FROM machine WHERE 'm_ipdb' LIKE :number OR 'm_name' LIKE :name";
$stmt = $dbh->prepare($sql);
$stmet->execute(array(
':number' => $_POST['searchText'],
':name' => $_POST['searchText']));
while ( $row = $stmt->fetch(PDO::FETCH_ASSOC) ) {
echo($row['m_ipdb']);
echo($row['m_name']);
}
?>
<p>Search for a Machine</p>
<form method="post">
<table width="500" border="1">
<tr>
<td>Enter IPDB Number or Name:</td>
<td><input name="searchText" type="text" id="searchText" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Search Database"></td>
<td><a href="#">Cancel</a></p></td>
</tr>
</table>
</form>
</body>
</html>
$stmet->execute to$stmt->execute?$stmet->execute to$stmt->execute?如果查询返回您真正需要的内容,您是否尝试过在sql中运行该查询?我认为一个查询中包含两个类似于
的error@Swellar当然是这样not@Phil我知道了,我以前没见过,很高兴知道您是否希望像一样在您的字段中搜索?如果是这样,则缺少通配符。像这样试试比如CONCAT(“%”,:number,“%”)
如果查询返回您真正需要的内容,您是否尝试过在sql中运行该查询?我认为在一个查询中使用两个比如error@Swellar当然是这样not@Phil我明白了,我以前没见过,很高兴知道你是否希望像
一样在你的领域内搜索?如果是这样,则缺少通配符。像这样试试<代码>如CONCAT(“%”,编号“%”)