简体   繁体   English

我试图在在线主机上运行我的网站,但我不断收到错误消息

[英]I am trying to run my website on an online host but i keep getting an error

Every time i am trying to run the following PHP code on 000Webhost, i keep getting this error -- mysqli_num_rows() expects parameter 1 to be mysqli_result. 每当我尝试在000Webhost上运行以下PHP代码时,我都会不断收到此错误-mysqli_num_rows()期望参数1为mysqli_result。

The same code had been run successfully without errors on my localhost, XAMPP, i have looked through many examples and only found out that this error is caused by an error in the query, but as mentioned, the query works perfectly on my localhost. 相同的代码已在我的本地主机XAMPP上成功运行且没有错误,我浏览了许多示例,才发现此错误是由查询中的错误引起的,但是如上所述,查询在我的本地主机上运行良好。

The error is indicated in the code. 错误在代码中指示。

Any help would be appreciated. 任何帮助,将不胜感激。

    <?php
    session_start();

    //decalre variables

    $DeviceID ="";
    $productID ="";


    //connect to database
    $db = mysqli_connect('localhost','id5655845_grocerywatch1234','123456','id5655845_grocerywatch1234');


    //validate product id and device id are avaliable

    if(isset($_POST['validate_user'])){
           $DeviceID = mysqli_real_escape_string($db,$_POST['DeviceID']);
           $productID = mysqli_real_escape_string($db,$_POST['productID']);


            $query = "SELECT * FROM configuration WHERE DeviceID='$DeviceID' AND productID='$productID'";
            $result1 = mysqli_query($db,$query);
            echo $query;

//error indicated on the following line.
            if(mysqli_num_rows($result1) == 1){
                $_SESSION['DeviceID'] = $DeviceID;
                $_SESSION['success'] = "You are now logged in";
                header('location: register.php');
            }
            else{
                echo "Device Not registered";
                echo "Product Doesnt Exist";
            }

    }

I think your query is likely failing. 我认为您的查询可能失败。 The return value for mysqli_query is False on failure, otherwise it is mysqli_result . 失败时mysqli_query的返回值为False ,否则为mysqli_result See docs here 在这里查看文档

Fix by properly formatting string: 通过正确格式化字符串来解决:

...
$query = "SELECT * FROM configuration WHERE DeviceID='".$DeviceID."' AND productID='".$productID."'";
$result1 = mysqli_query($db,$query);
echo $query;

if ($result1 == false){
    echo "Error has occurred!";
}
elseif (mysqli_num_rows($result1) == 1){
    $_SESSION['DeviceID'] = $DeviceID;
    $_SESSION['success'] = "You are now logged in";
    header('Location: register.php');
}
else{
    echo "Device Not registered";
    echo "Product Doesnt Exist";
}

The query either returned no rows or is erroneus, thus FALSE is returned. 该查询没有返回任何行,或者是错误的,因此返回FALSE。 Change it to 更改为

if (!$dbc || mysqli_num_rows($dbc) == 0)

Return Values 返回值

Returns TRUE on success or FALSE on failure. 成功返回TRUE,失败返回FALSE。 For SELECT, SHOW, DESCRIBE or EXPLAIN mysqli_query() will return a result object. 对于SELECT,SHOW,DESCRIBE或EXPLAIN,mysqli_query()将返回结果对象。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在尝试将其重写为mysqli查询,但我一直收到错误消息 - I am trying to rerwrite this as a mysqli query but I keep getting an error 我的网站的 wpadmin 无法正常工作,我收到此错误 - My website's wpadmin is not working and I am getting this error 尝试打开我的网站时,我不断收到此错误:SQLSTATE [28000] [1045]用户&#39;amaqhawe&#39;@&#39;localhost&#39;的访问被拒绝(使用密码:NO) - I keep getting this error when trying to open my website: SQLSTATE[28000] [1045] Access denied for user 'amaqhawe'@'localhost' (using password: NO) 为什么我会在我的网站上收到此通知 - why I am getting this notice in my website 我在 laravel 网站中收到错误 404 - I am getting error 404 in laravel website 为什么当我的php网页位于在线Web服务器上时,却无法发送会话Cookie错误? - why am i getting the cannot send session cookie error on my php webpage when it is in an online webserver? 我正在尝试在我的 Laravel 8 应用程序中上传个人资料图片。 但是,我不断收到“尝试读取数组上的属性“图像””错误 - I am trying to upload a profile image within my Laravel 8 application. I however keep getting "Attempt to read property "image" on array" error codeigniter错误:我试图运行我的项目,并从数据库中选择数据,但出现此错误: - codeigniter error: I am trying to run my project and Select data from the datatbase but I get this error: 我正在尝试通过我的应用程序下载文件,但出现此错误 - I am trying to download file through my application but am getting this error 当我尝试使用 4G 连接访问我的网站时出现空白页面(ssl 错误)? - Blank page (ssl error) when I am trying to access my website with a 4G connection?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM