title: INSERT INTO SQL result in empty elements being inserted
body: <p>Here is my code:</p>
  
  <pre><code>function register($user, $pass) {
      //check if username exists
      $login = query("SELECT username FROM login WHERE username='%s' limit 1", $user);
      if (count($login['result'])&gt;0) {
          errorJson('Username already exists');
      }
         //try to register the user
         $result = query("INSERT INTO login (username, pass) VALUES('%s','%s')", $user, $pass); 
          if (! $result['error']) {
          //success
          login($user, $pass);
          } else {
      //error
           //errorJson('Registration failed');
                errorJson($result['error']);
          }
  }
  
  
  
  function login($user, $pass) {
      $result = query("SELECT IdUser, username FROM login WHERE username='%s' AND pass='%s' limit 1", $user, $pass);
  
      if (count($result['result'])&gt;0) {
          //authorized
          $_SESSION['IdUser'] = $result['result'][0]['IdUser'];
          print json_encode($result);
      } else {
          //not authorized
          errorJson('Authorization failed');
      }
  }
  </code></pre>
  
  <p>I call register with username and password and both fields in the DB are empty. The insertion takes place normally because the primary key which is auto incremented is being increased- just the fields are empty.</p>
  
  <p>This is how I created my username.</p>
  
  <pre><code>CREATE TABLE `login` (
    `IdUser` int(11) NOT NULL AUTO_INCREMENT,
    `username` varchar(45) NOT NULL,
    `pass` varchar(45) NOT NULL,
    PRIMARY KEY (`IdUser`)
  ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  </code></pre>
  
  <p>and this is my query function:</p>
  
  <pre><code>//executes a given sql query with the params and returns an array as result
  function query() {
      global $link;
      $debug = false;
  
      //get the sql query
      $args = func_get_args();
      $sql = array_shift($args);
  
      //secure the input
      for ($i=0;$i&lt;count($args);$i++) {
          $args[$i] = urldecode($args[$i]);
          $args[$i] = mysql_real_escape_string($link, $args[$i]);
      }
  
      //build the final query
      $sql = vsprintf($sql, $args);
  
      if ($debug) print $sql;
  
      //execute and fetch the results
          $result = mysql_query($sql, $link);
      if (mysql_errno($link)==0 &amp;&amp; $result) {
  
          $rows = array();
  
          if ($result!==true)
          while ($d = mysql_fetch_assoc($result)) {
              array_push($rows,$d);
          }
  
          //return json
          return array('result'=&gt;$rows);
  
      } else {
  
          //error
          return array('error'=&gt;'Database error');
      }
  }
  </code></pre>
  
  <p>I have cheked that the $user, and $pass contain the correct value before executing the INSERT INTO.</p>