Jump to content

Warning: mysqli::query(): Couldn't fetch mysqli in C:\wamp\www\Entourage\class_func.php on line 55


talk2toyin

Recommended Posts

Hi gurus! I'm currently working on my website and I have ecountered this warning message "SCREAM: Error suppression ignored for

Warning: mysqli::query(): Couldn't fetch mysqli in C:\wamp\www\Entourage\class_func.php on line 55".

 

Here's a function I created "class_func.php":

<?php

/***connect to the database***/

$mysqli = new mysqli("localhost","root","","test");

if($mysqli->connect_errno) {

echo "Error: Connection To The Server Failed. " . ($mysqli->connect_errno) . $mysqli->connect_error;

}

/***End***/

$err = array();//set an array to hold all the errors that might be generated during login

/***Create a function that will handle the Login Form***/

function checkLogin() {

global $err;//declare the error array as global so it is available everywhere

global $mysqli;//declare the connection as global so it is available everywhere

for($i=0; $i<func_num_args(); $i++) { //get the number of arguments supplied(username & password)

$data[$i] = trim(htmlentities(strip_tags(func_get_arg($i))));//using a for loop, format these arguments

}

/**Search the users table if user exists**/

//my line 55 $res = $mysqli->query("SELECT * FROM users WHERE user_name = '$data[0]' AND user_pass = '$data[1]'");

echo "Error Executing Query: " . ($mysqli->connect_errno) . $mysqli->connect_error;

$num = $res->num_rows;

if($num < 1) {//if no user found

/* close result set */

$res->close();

$err[] = "-Invalid Username and/or Password!";

} else {

//fetch the result set

$obj = $res->fetch_object();

/***Assign the result sets to sessions***/

$_SESSION['user_name'] = $obj->user_name;

$_SESSION['user_id'] = $obj->user_id;

$logged = "Logged In";//set admin status to logged in

$update = $mysqli->query("UPDATE users

SET user_status = '$logged'

WHERE user_id = '{$_SESSION[user_id]}' && user_name = '{$_SESSION['user_name']}'");

/* close result set */

if($obj->user_level == "Admin") {

$update->close();

$res->close();

header('location:admin_page.php');

exit();

}

else {

$update->close();

$res->close();

header('location:members_page.php');

exit();

}

}

}

/***End of checkLogin function***/

?>

 

And this is my page "index.php" that calls this function:

<?php

 

include "class_func.php";

 

if(isset($_POST['login']) && $_POST['login'] == "Continue >>") {//if the login button has been clicked

/***Check to see if the user clicked the submit button without typing in any data***/

if(empty($_POST['username']) || empty($_POST['password'])) {

$err[] = "-Both Fields are Required Please!";

}

/***End***/

else {

 

//assign user inputs to variables

$username = $_POST['username'];

$password = $_POST['password'];

//call the checkLogin function to validate input

checkLogin($username, $password);

}

}

 

?>

Just like u can see, my form variables are username and password. Any help much appreciated

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.