ayoubel12 Posted July 7, 2022 Share Posted July 7, 2022 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. Quote Link to comment https://forums.phpfreaks.com/topic/315009-mysql-error-statements-not-working/ Share on other sites More sharing options...
Barand Posted July 7, 2022 Share Posted July 7, 2022 https://www.php.net/manual/en/mysqli.construct.php See example #3 - manual error handling Quote Link to comment https://forums.phpfreaks.com/topic/315009-mysql-error-statements-not-working/#findComment-1598053 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.