PHPremote Posted May 16, 2020 Share Posted May 16, 2020 (edited) My code here works in some locations but not others. I believe it may be due to a faulty database connection. The $dbconnection gets returned from a function intended for the purpose and then passed to functions as needed. I am getting this error message for a $conn->query("SELECT * FROM formstable"); : Quote Warning: mysqli::query(): Couldn't fetch mysqli in C:\xampp\htdocs\ ... (The warning goes on to specify the page and line number of course.) The code works within the database connection function just before my "return $conn;" statement. It works within a function "askQuery" called from one location but not anorher. It does not work at all in a function "showSelect". This seems the most relevant code: $newsqlStatement = showSelect($testConn, "SELECT * FROM formstable"); // will later isolate selectStatement WHERE formname = formname function showSelect($conn, $sqlStatement) { $result = $conn->query("SELECT * FROM formstable"); . ' ' return $successSelect; // for now just true or false } // end function showSelect Edited May 16, 2020 by PHPremote Link to comment Share on other sites More sharing options...
dsonesuk Posted May 16, 2020 Share Posted May 16, 2020 I assume its NOT as shown and function called, THEN defined in that order? Link to comment Share on other sites More sharing options...
PHPremote Posted May 20, 2020 Author Share Posted May 20, 2020 The function is defined in a file brought in via "include" . The call is in the main file. My intent is to search for a prepared MySQL search term corresponding to the form submitted, and any other corresponding queries like an insert. Link to comment Share on other sites More sharing options...
PHPremote Posted May 28, 2020 Author Share Posted May 28, 2020 It works now. I had called $conn->close(); immediately after establishing it. It was to deal with an earlier error, although I do not remember what. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now