无法从mysql表中选择用户。

I asked a question before about my code with submitting users. After a few days of just guessing, I finally got it working. But, now. I can't select the user inside the table for a login. This is my code.

<?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>

When I try to submit a user for it to identify/match, it doesn't and sends me straight into the game. Can someone help? A Beta is due in 3 days.!!!

You are not executing your query nor are you fetching the results:

$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'])

Additionally:

  • Where did $fname come from? Did you just make that up?
  • You don't seem to use your POST variables which are probably necessary for you to run your query and get an exact match for your user. The above code will return every user but only check the first one. I doubt that is what you want.
  • You have two POST variables that seem to hold a first name. Does that look correct to you?