PHP Blog Admin Panel 3: How to give database connection in php mysql | Connection to MySql DB in php

preview_player
Показать описание
In this video, I have taught how to give database connection in php mysql
Connection to MySql DB in php script.
PHP Blog Script in PHP MySQL Source Code:

Playlist - PHP Blog Admin Panel:

Part 1: PHP Blog: Setup Admin Panel in PHP

Part 2: PHP Blog: How to setup frontend part in php with navbar, login and register page

Part 3: PHP Blog: how to give database connection in php mysql

Рекомендации по теме
Комментарии
Автор

Awesome video. I did run into a problem with the dberror redirect, but fixed it by using a try-catch block in place of the if/else statement:

try{
$con = mysqli_connect($host, $username, $password, $database);
}catch(Exception $e){
header("Location: ../errors/dberror.php");
die();
}

TheQueenfGames
Автор

Thanks this tutorial series. I hope you will publish oop php tutorial series. Thanks

mdjabedbhuiyan
Автор

awesome tutorial so far however i wrote the code exactly how you do however if the database is not connected I was not redirected to another page instead I get a error of
Fatal error: Uncaught mysqli_sql_exception: Unknown database 'blowg' in Stack trace: #0 mysqli_connect('localhost', 'root', '', 'blowg') #1 #2 {main} thrown in on line 7
please could someone help

-dsenpai
Автор

PLEASE SURE I HAVE THE SAME PROBLEM AS low zhi lok can you help?

elmounchitayoub
Автор

I am not able to open my blogs in my website ? How can I identify a blog file in myphp data

paritoshpandya
Автор

Hello sir, I follow you the database connection but still cannot redirect to the dberror.php there. Can you hlp me?

This is index (In admin):
<?php
include('config/dbcon.php');

?>

<div class="container-fluid px-4">
<h1 class="mt-4">Welcom to the Admin Page!</h1>
<ol class="breadcrumb mb-4">
<li class="breadcrumb-item active">Dashboard</li>
</ol>

<div class="row">
<div class="col-xl-3 col-md-6">
<div class="card bg-primary text-white mb-4">
<div class="card-body">Primary Card</div>
<div class="card-footer d-flex align-items-center justify-content-between">
<a class="small text-white stretched-link" href="#">View Details</a>
<div class="small text-white"><i class="fas fa-angle-right"></i></div>
</div>
</div>
</div>
<div class="col-xl-3 col-md-6">
<div class="card bg-warning text-white mb-4">
<div class="card-body">Warning Card</div>
<div class="card-footer d-flex align-items-center justify-content-between">
<a class="small text-white stretched-link" href="#">View Details</a>
<div class="small text-white"><i class="fas fa-angle-right"></i></div>
</div>
</div>
</div>
<div class="col-xl-3 col-md-6">
<div class="card bg-success text-white mb-4">
<div class="card-body">Success Card</div>
<div class="card-footer d-flex align-items-center justify-content-between">
<a class="small text-white stretched-link" href="#">View Details</a>
<div class="small text-white"><i class="fas fa-angle-right"></i></div>
</div>
</div>
</div>
<div class="col-xl-3 col-md-6">
<div class="card bg-danger text-white mb-4">
<div class="card-body">Danger Card</div>
<div class="card-footer d-flex align-items-center justify-content-between">
<a class="small text-white stretched-link" href="#">View Details</a>
<div class="small text-white"><i class="fas fa-angle-right"></i></div>
</div>
</div>
</div>
</div>
</div>

<?php


?>

This is dbcon.php (In admin):
<?php

$host = "localhost";
$username = "root";
$password = "";
$database = "loa_music_website";

$con = mysqli_connect("$host", "$username", "$password", "$database");

if(!$con){
header("Location: ../errors/dberror.php");
die();
}

?>

This is dberror.php (Outside admin):

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Testing</title>
</head>
<body>

</body>
</html>

?>


why still cannot redirect to the "dberror.php"?

lowzhilok
Автор

I have done everything exactly, but it doesn't redirect to dberrors.php

this is the error I'm getting instead!

Warning: mysqli_connect(): (HY000/1049): Unknown database 'echrxsfsdspodvrt' in on line 8

Warning: Cannot modify header information - headers already sent by (output started at in on line 12

paapaak
Автор

Has anyone found a solution to redirecting to dberror.php? My code is exactly as it is in the video, but when I test with an incorrect database name, instead of redirecting to dberror.php, I get a "fatal error: Uncaught mysqli_sql_exception: Unknown database 'costingdfdfd'...."

crpvnum