ayoubel12
-
Posts
1 -
Joined
-
Last visited
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.
mysql error statements not working
in MySQL Help
Posted
Hello, please can someone help me? I want when the admin tries to connect using wrong database information to be redirected to an other error page but it don't work even if I try to echo a message. Here is my code containing wrong database name :
<?php
$host = "localhost";
$user = "root";
$pass = "";
$dbname = "ts";
$dbcon = mysqli_connect($host,$user,$pass,$dbname);
if($dbcon){
echo 'connection success';
}else{
header("Location: dberror.php");
die();
}
?>
Here is what displays to me instead of redirecting the user to the error page:
Fatal error: Uncaught mysqli_sql_exception: Unknown database 'ts' in C:\xampp\htdocs\tst\dbcon.php:7 Stack trace: #0 C:\xampp\htdocs\tst\dbcon.php(7): mysqli_connect('localhost', 'root', '', 'ts') #1 {main} thrown in C:\xampp\htdocs\tst\dbcon.php on line 7
I would want to know what's wrong?
Thanks in advance.