mysqli_result类的对象无法在简单查询中转换为字符串

时间:2016-04-21 01:31:42

标签: php

我试图找到类似的问题,但我无法解决。至少我没有理解答案。今天,我在创建一个简单的PHP脚本时遇到了很多麻烦。我暂时没有使用过php,所以我想要更新我的知识。

但是,当我尝试使用返回的回音结果进行简单查询时,它会说:

Catchable fatal error: Object of class mysqli_result could not be converted to string in /hermes/bosnaweb12a/b963/ipg.matjasicborutcom1/TouchSoccer/process.php on line 18

我记得我以前用这样的输出编码并查询相同但现在它不能正常工作......以下是代码:

<?php
    include 'dbinfo.php';
    $choice = $_GET['choice'];
    $connect = mysqli_connect($hostname, $username, $password, $database);
    if (mysqli_connect_errno($connect))
    {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    switch($choice)
    {
        case "register":

    $username = $_GET['username'];
    $password = $_GET['password'];
    $email = $_GET['email'];
    $reg_ip = $_GET['reg_ip'];


    $query = mysqli_query($connect, "SELECT username FROM Accounts WHERE username = '$username'");


    if($query) 
    {
        echo "username already exists";
    }   
    else {

        $insert = mysqli_query($connect, "INSERT INTO Accounts (username, password, email,reg_ip, wins, looses, experience) VALUES ('$username', md5('$password'), '$email',  '$reg_ip', '0','0', '0'");
        if($insert) {
                echo "account successfully created";

            } 
            else {
                echo "error";
            }

        }

        break;

        case "login":

        $username = $_GET['username'];
        $password = $_GET['password'];

        $user = mysqli_query($connect, "SELECT username FROM Accounts WHERE username = '$username'");

            if($user = $username) {
                $pw = mysqli_query($connect, "SELECT password FROM Accounts WHERE password = md5('$password')");

                if($pw = md5($password)) {
                    echo "login was successful!";
                }
                else {
                    echo "incorrect password";
                }

            }
        else 
{           
    echo "incorrect username";
        }



        break;


    }

mysqli_close($connect);
?>

1 个答案:

答案 0 :(得分:0)

在此代码之后:

      while (keyboard.hasNextDouble())
      {
         double input = keyboard.nextDouble();
         numbers.add(input);  
         if(input == -99)  break;
      }

$ user变量mysqli result object不是用户名字段的普通值,因此您无法将其与字符串变量进行比较。