talk2toyin Posted March 10, 2013 Share Posted March 10, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/275463-warning-mysqliquery-couldnt-fetch-mysqli-in-cwampwwwentourageclass_funcphp-on-line-55/ Share on other sites More sharing options...
talk2toyin Posted March 10, 2013 Author Share Posted March 10, 2013 These errors were also outputed: Notice: Trying to get property of non-object in C:\wamp\www\Entourage\class_func.php on line 56 Fatal error: Call to a member function close() on a non-object in C:\wamp\www\Entourage\class_func.php on line 59 Quote Link to comment https://forums.phpfreaks.com/topic/275463-warning-mysqliquery-couldnt-fetch-mysqli-in-cwampwwwentourageclass_funcphp-on-line-55/#findComment-1417831 Share on other sites More sharing options...
talk2toyin Posted March 10, 2013 Author Share Posted March 10, 2013 The line 56 is: $num = $res->num_rows; And line 59 is: $res->close(); Quote Link to comment https://forums.phpfreaks.com/topic/275463-warning-mysqliquery-couldnt-fetch-mysqli-in-cwampwwwentourageclass_funcphp-on-line-55/#findComment-1417832 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.