I have a question... why are you wasting time using complex string parsing when you're just passing the values?!? Lose the quotes on the things that don't need quotes! Likewise, try to use singles not doubles unless you REALLY need it.
$con = mysqli_connect('localhost', $username, $password, $db_name);
You don't need quotes on those when passing them from variables. Unlikely that was the problem, but it can't be helping.
Though I'd probably also swing an axe at the procedural style calls since they add a little overhead for nothing -- but that's why I use PDO.
$con = new mysqli('localhost', $username, $password, $db_name);
Also, are you SURE those variables are in scope of where you're calling them? (NOT that I'd store that stuff in global scope, but that's a whole other topic called "security")