php warning: mysqli_close() expects parameter 1 to be mysqli
mysqli_close($result);
The line above is incorrect. You only need to call mysqli_close()
once (if at all since, as pointed out in the comments, the connection is closed at the end of the execution of your script) and the parameter should be your link identifier, not your query resource.
Remove it.
Warning: mysqli_close() expects parameter 1 to be mysqli
You don't need this line:
mysqli_close($result);
You only need to close the connection.
mysqli_close() expects parameter 1 to be mysqli, null given
Make $con
a private variable outside of the function.
<?php
/**
* A class file to connect to database
*/
class DB_CONNECT {
private $con = null;
// constructor
function __construct() {
}
// destructor
function __destruct() {
// closing db connection
$this->con = null;
}
/**
* Function to connect with database
*/
function connect() {
// import database connection variables
require_once __DIR__ . '/db_config.php';
// Connecting to mysql database
$this->con = mysqli_connect(DB_SERVER,DB_USER,DB_PASSWORD,DB_DATABASE) or die("Data base connection failed....! " . mysqli_error($con));
// returing connection cursor
return $this->con;
}
/**
* Function to close db connection
*/
function close() {
// closing db connection
mysqli_close($this->con);
}
}
?>
Then you can access it throughout the class. Also in your constructor call the connect
function to ensure that the first thing it does is connect.
Edit 1
From what I can see your naming convention is a bit off too. Your class name DB_CONNECT
looks like a const
because that's how you have specified them in your db_config.php
.
Warning: mysqli_error() expects parameter 1 to be mysqli, null given in /users/mikadoru/www/register.php on line 16
You are not opening any DB!
From PHP manual:
mysqli_connect($db_host,$db_user,$db_pass,$db_database,$db_port);
mysqli_query() and mysqli_close expects parameter 1 to be mysqli - PHP
$mysqli
is not defined anywhere in your first script. It looks like you meant to include the second script at the top of the first one, but you didn't. So do that and your problem will go away.
<?php
session_start();
include("WhateverThatOtherScriptIsCalled.php");
...
Related Topics
Woocommerce: Display Some Reviews Randomly on Home Page
Compile Error: Cannot Use Isset() on the Result of an Expression
How to Add Dynamic Dropdown List Column on Laravel 5.3 Registration
Check If Url Has Certain String with PHP
How to Downgrade or Install a Specific Version of Composer
Codeigniter Multiple File Upload Messes File Extension
How to Rotate Image and Save the Image
Performance in Pdo/Php/Mysql: Transaction Versus Direct Execution
(Mysql, PHP) How to Get Auto_Increment Field Value Before Inserting Data
How to Query All the Graphql Type Fields Without Writing a Long Query
Detect Exif Orientation and Rotate Image Using Imagemagick
How to Use Break or Continue Within for Loop in Twig Template
Non-Breaking Utf-8 0Xc2A0 Space and Preg_Replace Strange Behaviour