title: PHP Register Script - check user exists not working
body: <p>I've got a problem with my PHP Registration Script that firstly checks, if the user exists.</p>
  
  <p>It always outputs "false".</p>
  
  <pre><code>&lt;?php
  $username = $_GET['username'];
  $passwort = $_GET['passwort'];
  
  $database = @mysql_connect("***********", "********", "******") or die("Can't connect to the server. Error: ".mysql_error());
  //$username = mysql_real_escape_string($username);
  $passwort = hash("sha256", $passwort);
  
  $numrows = mysql_query("SELECT * FROM *******.mikgames WHERE username='".$username."' LIMIT 1"); 
  $checkuserexists = mysql_num_rows($numrows);
  
  if($checkuserexists==0) {
  $abfrage = mysql_query("INSERT INTO *******.mikgames (username,passwort) VALUES ('$username', '$passwort')");   
  echo'true';
  }
  else {
  echo'false';
  }        
  ?&gt;
  </code></pre>
  
  <p>Edit: Now I'am using MySQLi and I've changed the code into this:</p>
  
  <pre><code>&lt;?php
  $username = $_GET['username'];
  $passwort = $_GET['passwort'];
  
  $con = mysqli_connect('************','******','******') or     die(mysqli_error());
  mysqli_select_db($con, "*******") or die("cannot select DB");
  
  $passwort = hash("sha256", $passwort);
  
  $query = mysqli_query($con,"SELECT * FROM *******.mikgames WHERE     username='".$username."'");
  $result = mysqli_num_rows($query);
  
  if($result==0) {
  $abfrage = mysqli_query($con, "INSERT INTO ********.mikgames (username,passwort) VALUES ('$username', '$passwort')");   
  $result = mysqli_query($con,$abfrage);
  echo 'true';
  }
  else {
  echo 'false';
  }        
  ?&gt;
  </code></pre>
  
  <p>And it works.</p>