title: Php/Sql if exists update else insert not working
body: <p>Hi I'm trying to save player information and update it if information already exists but I can't seem to figure out why my query won't work. 
  it looks sound to me.</p>
  
  <pre><code>&lt;?php
  include("DBTools.php");
  $link=dbConnect();
  
  $name = safe($_POST['name']);
  $level = safe($_POST['level']);
  $experiance = safe($_POST['experiance']);
  $health = safe($_POST['health']);
  $maxHealth = safe($_POST['maxHealth']);
  
  $posx = safe($_POST['posx']);
  $posy = safe($_POST['posy']);
  $posz = safe($_POST['posz']);
  
  
      $query = "IF EXISTS(select * from 'PlayerStats` where name = '$name') UPDATE 'PlayerStats` SET level = '$level', experiance = '$experiance', health = '$health', maxHealth = '$maxHealth',posx = '$posx', posy = '$posy', posz = '$posz' WHERE name = '$name' ELSE INSERT INTO `PlayerStats`(`name`, `level`, `experiance`, `health`,`maxHealth`, `posx`, `posy`, `posz`) VALUES ('$name','$level','$experiance','$health','$maxHealth','$posx','$posy','$posz')";
      $result = mysql_query($query) or die('Query failed: ' . mysql_error());
  </code></pre>
  
  <p>?></p>
  
  <p>i don't really have access to any logs so i cant see any errors </p>
  
  <p>I have also tried this which doesn't work either</p>
  
  <pre><code>$sql = "SELECT * FROM PlayerStats` WHERE name = '$name'";
  $result = mysql_query($sql);
  if(mysqli_num_rows($result) !== 1){
      $query = "INSERT INTO `PlayerStats`(`name`, `level`, `experiance`, `health`,`maxHealth`, `posx`, `posy`, `posz`) VALUES ('$name','$level','$experiance','$health','$maxHealth','$posx','$posy','$posz')";
      $result = mysql_query($query) or die('Query failed: ' . mysql_error());
  }else{
      $query = "UPDATE `PlayerStats` SET level = '$level', experiance = '$experiance', health = '$health', maxHealth = '$maxHealth', posx = '$posx', posy = '$posy', posz = '$posz' WHERE name = '$name';
      $result = mysql_query($query) or die('Query failed: ' . mysql_error());
  }
  </code></pre>
  
  <p>if i just insert it works fine but its just when i try and update nothing works</p>