See
PHP: mysqli::select_db - Manual[
^]. The first argument is the connection and the second is the name but you are passing them reversed.
It must be
$db=mysqli_select_db($con,DB_NAME) or die("Failed to connect to database: " . mysqli_error());
[EDIT]
Because you are using the procedural style, you have to use it too for the error function. Note also that
mysqli_error()
can't be used when connecting fails. You have to use
mysqli_connect_error()
instead:
$con=mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD) or die("Failed to connect to MySQL: " . mysqli_connect_error());
$db=mysqli_select_db($con,DB_NAME) or die("Failed to connect to database: " . mysqli_error($con));
[/EDIT]
[EDIT2]
And similar for all other SQL operations where you did not pass the connection/link
$con
.
[/EDIT2]