Your parameters are in the wrong order, read the documentation again. For example:
$username = mysqli_real_escape_string(trim($_POST["username"]), $db);
Should be:
$username = mysqli_real_escape_string($db, trim($_POST["username"]));
See http://php.net/mysqli_real_escape_string (the procedural style) for the right parameter order.
5
solved warning of mysqli_real_escape_string() for this code [closed]