" mysqli_num_rows"尽管有多个具有这些值的SQL条目,但仍保持返回零

时间:2016-10-01 18:32:28

标签: php mysqli

编辑:感谢所有帮助解决此问题的人!我将仔细研究其他讨论引号使用的帖子。

我仍然是一个PHP新手,学习摆弄代码片段。所以请不要对我太过刻苦。我也知道下面的代码容易受到sql注入攻击。但我只是用它来测试和练习我的第一个PHP课程。事情有望在某些时候变得更专业......

暂时我遇到了以下问题:mysqli_num_rows总是返回0.我没有语法错误暗示我做错了什么。但是某处应该存在语法错误,因为它不是说已经存在具有相同值的SQL条目,而是创建双倍,三元组等等......具有更多经验的人能否告诉我我可能做错了什么?

非常感谢!

   <?php

   $con=mysqli_connect("database-connection data in here");
   // Check connection
   if (mysqli_connect_errno()) {
   echo "Failed to connect to MySQL: " . mysqli_connect_error();
   }


    $gameName = mysqli_real_escape_string($con, $_POST['gameName']); 
    $playerKey = mysqli_real_escape_string($con, $_POST['playerKey']); 
    $creatorKey = mysqli_real_escape_string($con, $_POST['creatorKey']);


    $query = mysqli_query($con,"SELECT * FROM SAGS_global_players WHERE CreatorKey = '.$creatorKey.' AND GameName = '.$gameName.' AND PlayerKey = '.$playerKey.'");

    mysqli_store_result($con);
    $row_cnt = mysqli_num_rows($query);
    echo "number of entries with same data = ".$row_cnt.".";

    if ($row_cnt == 0) 
      {
       //create a new database entry for the new player
      }
    else
      {
        // show the saved results for this player from database and send via http-bridge to game
      }

    mysqli_close($con); ?>

0 个答案:

没有答案