php mysql阿拉伯语搜索

时间:2014-01-25 19:48:16

标签: php mysql forms

我正在尝试在mysql db中搜索一个阿拉伯语单词,当我执行查询时它运行完美如果我把单词my self但是当使用POST中的变量时我得到此错误     mysqli_fetch_array()期望参数1为mysqli_result,给定布尔值 这是我的代码:

 <form method="post" action="closedreq.php" target="_self">
<p>Search For Request : </p>
<input type="text" name="search" />
<input type="submit" value="Submit" name="submit" id="submit" />
</form>
</div>
<?php 
if (isset($_POST['submit'])){
    $search = $_POST['search'];
    $sql = mysqli_query($con,"select * from new_req where status = '0' AND (id = $search or req_city = $search
    or req_location  = $search or req_date = $search ) order by id desc");

当我回显变量时,输出就像我想要的那样

1 个答案:

答案 0 :(得分:0)

您必须将搜索字符串放在引号中。您还应该转义发送到数据库的所有用户输入。

 <form method="post" action="closedreq.php" target="_self">
<p>Search For Request : </p>
<input type="text" name="search" />
<input type="submit" value="Submit" name="submit" id="submit" />
</form>
</div>
<?php 
if (isset($_POST['submit'])){
    $search = mysqli_escape_string($con, $_POST['search']);
    $sql = mysqli_query($con,"select * from new_req where status = '0' AND (id = '$search' or req_city = '$search'
    or req_location  = '$search' or req_date = '$search' ) order by id desc");