2014-01-25 74 views
0

我想在mysql数据库中搜索一个阿拉伯文字当我做查询它运行完美,如果我把这个词我自己但是当使用POST变量时我得到这个错误 mysqli_fetch_array()期望参数1被mysqli_result,布尔给 这是我的代码:php mysql阿拉伯语搜索

<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"); 

当我回声变量输出是像什么,我想

+0

请参阅[此答案](http://stackoverflow.com/a/11674313/250259)了解如何解决此问题。 –

+0

不,当我搜索其他英文的东西时,它的工作原理 –

+0

你的代码可以被SQL注入,并且会被滥用。神奇地将'mysql_'改为'mysqli_'并不能解决这个问题。使用准备好的语句并绑定变量,或者至少在您的字符串中使用'mysqli_real_escape_string',然后将它们粘贴到查询中。 – h2ooooooo

回答

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"); 
+0

同样的问题 –

+0

我能想到的唯一的事情就是你的一个列或表的命名是不同的。 – Mixthos

+0

您可能想在查询之后添加'echo mysqli_error($ con);'以获取SQL错误。 – Mixthos