查询总是返回false - PHP MYSQL

时间:2017-09-20 16:41:42

标签: php mysql

我有一个用于登录的php页面(没有任何保护,我将来会设置它们)但每次运行任何查询时,即使是简单的SELECT * FROM 'player'$risultato也始终为false 。我已经检查过所有连接信息都是正确的(它们在注册页面中工作)。有人知道为什么吗?

的login.php

<?php  

    $connessione = mysqli_connect("localhost", "my_id", "my_pass", "my_db");

    $user_name = $_GET['user_name'];  

    $user_pass =  $_GET['user_pass'];

    $query = "SELECT username FROM 'player';";

    $risultato = mysqli_query($connessione, $query); <---- !!always false!!

    $count = mysqli_num_rows($risultato); <---- it say that he receved a boolean (false)

    if ($count != 1) {
        echo "Nessun risultato.";
    }else{

        $row = mysqli_fetch_assoc($risultato);  

        $name = $row['username'];  


}

编辑:

我的工作register.php:

<?php  

 $connessione = mysqli_connect("localhost", "my_id", "my_pass", "my_db");

 $user_name = $_POST['user_name']; 

 $user_pass = $_POST['user_pass'];  

 $query =  "INSERT INTO `player` (`username`, `password`, `money`) VALUES ('".$user_name."', '".$user_pass."', '100');";

 $risultato = mysqli_query($connessione, $query);

if($risultato){
 http_response_code(200);
}else{
 http_response_code(400);
}

编辑#2:

这也不起作用:

<?php  

$connessione = mysqli_connect("localhost", "id2967178_fyruz", "Ferru9800", "id2967178_collectcards");
echo mysqli_error($connessione);
$user_name = $_GET['user_name'];  

$user_pass =  $_GET['user_pass'];

$query = "SELECT username FROM `player`";

$risultato = mysqli_query($connessione, $query);

$count = mysqli_num_rows($risultato);

if ($count != 1) {
    echo "Nessun risultatooooo.";

}else{

    $row = mysqli_fetch_assoc($risultato);  

    $name = $row['username'];  


}

1 个答案:

答案 0 :(得分:2)

这里的问题是您使用了错误的引号。它应该是:

SELECT username FROM `player`

单引号仅用于分隔字符串和字符串。

这只是一个问题,但是,还有很多其他问题,比如为什么要从该表中获取所有名称,以及你在做什么{{1变量。