$sql="SELECT * FROM Users WHERE '$searchType' = '$search'";
searchType 是列,search 是我要搜索的内容。
我已经检查了我的表单,它正在发布值,但当它到达我的 sql 时失败。
成功连接到数据库类型: - cusName值: - Fred0搜索结果
<form id="form1" name="form1" method="POST" action="search.php">
<p>
<label for='name' >Search for a customer: </label>
<input type='text' name='search' id='customername' maxlength="45" required/>
</p>
<input type="hidden" name="searchType" value="cusName"/>
<input type='submit' name='submit' value='Submit'/>
</form>
最佳答案
在查询字符串中使用未绑定(bind)的参数并不是最佳实践。但为了解决当前问题,您应该将单引号替换为列名称周围的反引号:
$sql="SELECT * FROM Users WHERE `$searchType` = '$search'";
关于php - 使用 mySQL 在 PHP 中 SQL 不返回结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30203518/