Jump to content

mysql error statements not working


ayoubel12

Recommended Posts

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.

 


 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.