I am getting this warning:
( ! ) Warning: mysqli_query() expects parameter 1 to be mysqli, null given in C:\wamp\www\inc\functions.php on line 73
Call Stack
# Time Memory Function Location
1 0.0003 251048 {main}( ) ..\manage_user.php:0
2 0.0012 295000 find_all_users( ) ..\manage_user.php:8
3 0.0012 295376 mysqli_query ( ) ..\functions.php:73
Database query failed.
I have read a few of the posts on it and from what understand the error is in the first string in my mysqli_query( $db , $query ).
This would be $db this is what i find strange. mysqli_query($db,$query)works for all the other functions just fine. but when i call find_all_users() function i get the warning.
dbcon:
define("DB_SERVER", "localhost");
define("DB_USER", "*******");
define("DB_PASS", "*******");
define("DB_NAME", "*******");
// 1. Create a database connection
$db = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME);
// Test if connection succeeded
if(mysqli_connect_errno()) {
die("Database connection failed: " .
mysqli_connect_error() .
" (" . mysqli_connect_errno() . ")"
);
}
functions:
function find_all_users() {
global $db;
$query = "SELECT * ";
$query .= "FROM user ";
$query .= "ORDER BY username ASC";
$user_set = mysqli_query($db, $query);
confirm_query($user_set);
return $user_set;
}
function confirm_query($result_set) {
if (!$result_set) {
die("Database query failed.");
}
}
the page i am getting the warning on:
<?php
require_once($_SERVER['DOCUMENT_ROOT'].'/session/session.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/inc/functions.php');
include($_SERVER['DOCUMENT_ROOT'].'/inc/header.php');
include($_SERVER['DOCUMENT_ROOT'].'/inc/nav_ribbon.php');
$user_set = find_all_users();
?>
<body>
<div id="p2dbg">
<div id="p2dcontent">
<?php include($_SERVER['DOCUMENT_ROOT'].'/inc/left_container.php'); ?>
<div id="page">
<?php echo message(); ?>
</div>
</div>
<?php include($_SERVER['DOCUMENT_ROOT'].'/inc/footer.php'); ?>
</div>
</body>
</html>
$db
was null
because dbcon
file was not being included:
include('dbcon.php');
session_start();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.