Home > database >  php Failed connection to database [closed]
php Failed connection to database [closed]

Time:10-06

<?php

 function connect()
{
    return mysqli_connect("localhost", "st1ik", "", "sitike");
}

ini_set('display_errors', 1); error_reporting(~0);

require 'connection.php';
$conn    = connect();
$query   = mysqli_query($conn,"INSERT into Members (Username) VALUES('1821Username')");

if (!$query) {
die("Couldn't enter data: ".$conn->error);

}

echo "Thank You For Contacting Us <br>";

mysqli_close($conn);

?>

this my code but it give me this error

Blockquote Fatal error: Uncaught Error: Failed opening required 'connection.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\chabka-stike\app\database\connect.php:10 Stack trace: #0 {main} thrown in C:\xampp\htdocs\chabka-stike\app\database\connect.php on line 10

CodePudding user response:

You can use below

require_once (dirname(__FILE__)."\connection.php");

Another option is to update the php.ini "include_path" setting to include the folder which contains "connection.php"

CodePudding user response:

As per error, There no any connection.php file. You should remove line called

require 'connection.php';

You have already connection information in connect function. Thanks!

CodePudding user response:

It seems that you wanted to load a file connection.php who's not a the right place (root of your file) or not exists.

  • Related