I have a database called "mp_users" with the following setup:
CREATE TABLE IF NOT EXISTS `mp_users` (
`id` int(10) unsigned default NULL auto_increment,
`uid` int(10) unsigned NOT NULL,
`username` varchar(100) NOT NULL,
`email` varchar(50) NOT NULL,
`points` int(10) unsigned NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
When I try to run the following query, I get an error:
Error:
Fatal error: Call to a member function query() on a non-object in /home/user/public_html/marketplace-functions.php on line 52
Here is the code:
<?php
require_once "config.php";
$sql = new mysqli($db1['host'], $db1['user'], $db1['pass'], $db1['db']);
function checkUserExists($uid){
// Query
$q = "SELECT COUNT(id) AS user_exists FROM `mp_users` WHERE uid=$uid LIMIT 1;";
echo $q;
$q = $sql->query($q);
$r = $q->fetch_assoc();
// Any results?
if($r['user_exists'] == 0){
// redirect to runonce...
header('Location: marketplace.php?do=runonce&return='.urlencode($_SERVER['QUERY_STRING']));
exit();
}
}
?>
Line 52 is the $q query.
I really cannot see what the problem is. The database exists, I've tried it in phpMyAdmin and it runs without trouble, but this wont!
Can anyone help?
Thanks in advance