Php mysql代码返回错误

时间:2013-09-07 16:52:36

标签: php mysql

使用我在这里的代码,我收到错误

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /home2/docvet95/public_html/personalcelebinfo.com/test/download.php on line 13
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''download-check' where ip='66.57.14.96'' at line 1

我不明白为什么。

<?php
    $ip = $_SERVER['REMOTE_ADDR'];
    echo $ip;
    $con=mysqli_connect("localhost","docvet95_check","%tothemax%","docvet95_downcheck");
    if (mysqli_connect_errno())
    {
       echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    $result = mysqli_query($con,"SELECT ip FROM 'download-check' where ip='$ip'");

    while ($row = mysqli_fetch_array($result))
    {
       echo $row['ip'];
       echo $row['files'];
       echo $row['downloads'];
    }

1 个答案:

答案 0 :(得分:1)

您的查询失败并返回false而不是结果集:

SELECT ip FROM 'download-check' where ip='$ip'

您的查询问题是您在数据库名称周围使用'。您的查询的此修改版本应该有效:

SELECT ip FROM `download-check` where ip='$ip'