last day (14 days later) » 

1:40 PM
0
Q: Call to a member function query() on a non-object - Not mixing MYSQL

Bradly SpicerI'm having the error: Fatal error: Call to a member function query() on a non-object in /home/content/58/12052758/html/template/sections/header.php on line 34 Which I know is commonly found when mixing MySQL and MySQLi, however I'm not mixing them. Here is header.php: http://pastebin.com...

 
Hm... - Hard to say. Make sure short open tags are on. <?=$showComments?> to <?php echo $showComments?> and all other <?= to <?php echo and <? to <?php - Edit: Reeno's comment makes sense. Show us what's inside header.php
I see 2 different DB connection variables $link->query and $db->query so there ya go ;) $db->query should most likely be $link->query IF that is the common variable denominator. I've got my money on $db => $link
 
@Reeno Updated and added header.php
@Fred-ii- Still receiving the same error on line 34 of header... I've updated header.php above
 
You're doing it again with $db->query in $qSettings = $db->query("SELECT and others. Choose ONE DB variable. What is your DB connection look like?
 
@Fred-ii- Neither are using $db now. I'm just reupdating the OP.
 
You're DB connection should look something like this $db = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME); or $link. All of your queries should reflect the use of the common DB variable denominator being $db or $link, don't mix them.
Well it sounds/looks to me that you're not including your DB connection anywhere; are you?
 
1:40 PM
@Fred-ii- They aren't mixing. I removed all the $db entries. Look above. Here is my database file: pastebin.com/dZGEisM2
 
Your DB file contains 2 instances for connection; why? This $link = mysqli_connect($db_host,$db_user,$db_pass,$db_name) or die("Error " . mysqli_error($link)); shouldn't be there. Remove it and replace $db = new mysqli($db_host, $db_user, $db_pass, $db_name); with $link = new mysqli($db_host, $db_user, $db_pass, $db_name); or remove $db = new mysqli($db_host, $db_user, $db_pass, $db_name); /* check connection */ if ($db->connect_errno) { printf("Connection failed: %s\n", $db->connect_error); exit(); } and keep the last one.
 
@Fred-ii- I'm using $link. Not $db.
Fred, would you mind jumping in chat. It's getting a bit too long.
 
hi
 
Hi, Sorry this is a project I've picked up after two other developers dropped it. I said I'd have a go at cleaning it up and putting the basics back together. It's just been a pain from the word go
 
about your DB connection pastebin file pastebin.com/dZGEisM2 you see where you're using 2 different connections?
this $link = mysqli_connect($db_host,$db_user,$db_pass,$db_name) shouldn't be used
 
1:41 PM
pastebin.com/7EHttziJ I changed it to this
 
ok, I see it. Now problem is, you have 2 instances of $db which all should be $link
$link = new mysqli($db_host, $db_user, $db_pass, $db_name);

/* check connection */
if ($link->connect_errno) {
printf("Connection failed: %s\n", $link->connect_error);
exit();
 
One second Fred, this has multiple instances of dbconfig.php
I'm going to make one instance.
You know, I can't even see where it's calling the database :/
 
ah well that added bit could do it (wink)
or... Missing I should say lol
 
It is definitely connected though :P as it's pulling old comments
 
ok well right now you have $link = new mysqli($db_host, $db_user, $db_pass, $db_name);

/* check connection */
if ($db->connect_errno) {
printf("Connection failed: %s\n", $db->connect_error);
exit();
}

where it should read as

$link = new mysqli($db_host, $db_user, $db_pass, $db_name);

/* check connection */
if ($link->connect_errno) {
printf("Connection failed: %s\n", $link->connect_error);
exit();
}
you're also setting error reporting to off with error_reporting(0); --- Use error_reporting(E_ALL); ini_set('display_errors', 1);
and this $query=mysqli_query($link,"select email from users");
$email=$link->query($query); you're querying twice.
and am having trouble figuring out which one should change and to "what".
 
1:51 PM
One second Fred :)
 
ok - in the meantime, this $email=$link->query($query); should probably be $email=$query; since as I said, you're using query twice, being mysqli_query and the $link->query
that alone will/could cause the error
 
But if there was an error I wouldn't be able to post would I?
The comment goes through, it's the JQuery refreshing which is buggering it up I think. although you are correct. That query is wrong ;P
 
Post? what do you mean by that?
 
When I submit the form it adds a comment to a video
that's when the error comes up
however, if I revisit that page... the comment is there AND in the database
 
the non-object error; that is one broad error lol - submit and querying are two different animals altogether ;)
it's your query then; the way I told you before.
 
1:54 PM
one second then i'l fix that email->$link
 
$query=mysqli_query($link,"select email from users");
$email=$query;
if(isset($email[0])){
$query1=mysqli_query($link,"select id from user where email='".$email[0]."' and facebook=1");
$admin=$query1;
$userId=$admin[0];
}
 
so that's what you're using now and is producing the same error?
 
Now the rest of the page from that point is white space
ahh because i still have error_reporting(0);
I've slowly been in the process of converting all the mysql to mysqli from the previous dev
so wow XD
 
I visited the page; did you the error messages? They contain mysql_ functions
did you see
 
2:00 PM
I did see :P
 
Warning: mysql_query() Warning: mysql_query() [function.mysql-query]: A link to the server coul.... Warning: mysql_fetch_row() expects parameter 1 t
I think you're going to need to rebuild from the ground up
 
It's been a matter of hooking all the old stuff and removing the crap tbh
 
start by using queries that work, one by one and go from there. There's not much else I can do here my friend
 
Thanks Fred
 
If you build from queries that fail, the rest will ;)
and you're welcome.
Enjoy your day. My 2nd cup of coffee's waiting for me, cheers
 
2:05 PM
:P thanks dude
 
you're welcome. ciao
 
2:16 PM
I don't suppose you know what the replacement for if(isset is in mysqli
$row = $result->fetch_array(MYSQLI_ASSOC); :P
 

last day (14 days later) »