无法从mysql表中选择用户。

时间:2014-04-04 14:23:12

标签: php mysql

我在提交用户之前提出了一个关于我的代码的问题。经过几天的猜测,我终于开始工作了。但现在。我无法在表格中选择用户进行登录。这是我的代码。

<?php 
   if($_POST['submit_id'] == 1)
    {

    //echo $_POST['fname'];

    $playerf = $_POST['fname'];
    $playerl = $_POST['lname'];
    $name = $_POST['firstname'];

    $link = mysqli_connect("localhost","tester","abc123","biscuit") or die(" Did not connect. " . mysqli_error($link));
    $query = "SELECT firstname FROM Users" or die("Did not work." . mysqli_error($link));

    if($name != $fname)
      {
      echo "Does not match.";
      }

    else
      {
    header ("Location: game.php");
      }

    } 
  ?>





    <table align = "center">
      <tr>
    <td>

      Welcome to <b> Besco's Biscuits </b>. Please fill out the following <br />
      areas and we will begin your adventure soon. :)

      </td>
    </tr>
    </table>
    <br /> <br /> <br /> <br /> <br />


    <table align = "center">
      <tr>
    <td> 

       <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post" > <br />
        Firstname: <input type="text" name="fname" id= "fname" required = "1"> <br />
        Lastname: <input type = "text" name = "lname" id= "lname" required = "1"> <br />

        <input type = "submit" value = "Register" id="submit_id" > &nbsp; &nbsp; 
         <input name="submit_id" type="hidden" id="submit_id" value="1">
        <input type = "reset" name="Reset" value="Reset Page" class = "account">

      </form>
    </td>
      </tr>
    </table>

当我尝试提交用户进行识别/匹配时,它并没有直接将我发送到游戏中。有人可以帮忙吗?测试版将在3天内到期。!!!

1 个答案:

答案 0 :(得分:3)

您没有执行查询,也没有获取结果:

$query = mysqli_query($link, "SELECT firstname FROM Users") or die("Did not work." . mysqli_error($link));
$user = mysqli_fetch_assoc($link, $query);
if($name != $user['firstname'])

此外:

  • $fname来自哪里?你刚刚完成了吗?
  • 您似乎没有使用POST变量,这些变量可能是您运行查询并获得用户完全匹配所必需的。上面的代码将返回每个用户,但只检查第一个。我怀疑那是你想要的。
  • 您有两个似乎拥有名字的POST变量。这看起来对你不对吗?