Here is my code:
require "../include/functions.php"; error_reporting(E_ALL); ini_set('display_errors', '1'); ConnectWithMySQLiDatabase(); $Cat = addslashes($_POST["Category"]); $v = $conn->mysqli_query($conn,"SELECT * FROM `categories` WHERE `id`=$Cat"); $vrowi = mysqli_fetch_array($v, MYSQLI_ASSOC); $url = $conn->real_escape_string($vrowi['Link']);
Here is what I have in functions.php :
function ConnectWithMySQLiDatabase() { global $dbhost, $dbuser, $dbpass, $database, $HTTP_SERVER_VARS; $conn = new mysqli($dbhost, $dbuser, $dbpass, $database); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $conn->set_charset("utf8"); global $conn; }
The variables $dbhost, $dbuser, $dbpass, $database, set correctly.
When I try to execute this mysqli_query, I get the following error:
<b>Fatal error</b>: Call to a member function mysqli_query() on a non-object in <b>/fetch_category_products.php</b> on line <b>19</b><br />
Line 19:
$v = $conn->mysqli_query($conn,"SELECT * FROM `categories` WHERE `id`=$Cat");
Could you tell me where is my mistake, and how can I fix it?
Thanks in advance!
source share