juelpatwary Posted April 3, 2008 Share Posted April 3, 2008 Hi, On my game website i get this error Fatal error: Call to a member function query() on a non-object in /home/bfp111/public_html/carmarket.php on line 31 And on line 31 it says this $q=$db->query("SELECT cm.*, u.*,ct.* FROM carmarket cm LEFT JOIN users u ON u.userid=cm.cmADDER LEFT JOIN cars_types ct ON ct.carID=cm.cmCAR ORDER BY cmPRICE ASC",$c); These are lines 25 to 35 (If needed) function cmarket_index() { global $ir,$c,$userid,$h; print " Viewing all listings... <table width=100% border=6> <tr style='background:#cc9966'> <th>Seller</th> <th>Car</th> <th>Acceleration Level</th> <th>Handling Level</th> <th>Speed Level</th> <th>Shield Level</th> <th>Price</th> <th>Links</th> </tr>"; $q=$db->query("SELECT cm.*, u.*,ct.* FROM carmarket cm LEFT JOIN users u ON u.userid=cm.cmADDER LEFT JOIN cars_types ct ON ct.carID=cm.cmCAR ORDER BY cmPRICE ASC",$c); while($r=mysql_fetch_row($q)) { if($r['cmADDER'] == $userid) { $link = "<a href='carmarket.php?action=remove&ID={$r['cmID']}'>Remove</a>"; } else { $link = "<a href='carmarket.php?action=buy&ID={$r['cmID']}'>Buy</a>"; } print "\n<tr> <td><a href='viewuser.php?u={$r['userid']}'>{$r['username']}</a> [{$r['userid']}]</td> <td>{$r['carNAME']}</td> <td>{$r['cmACC']}</td> <td>{$r['cmHAN']}</td> <td>{$r['cmSPD']}</td> <td>{$r['cmSHD']} <td>\$".number_format($r['cmPRICE'])."</td> <td>[$link]</td> </tr>"; Anyway, I please hope you can help me, I just dont get the error as i said, The error is this Fatal error: Call to a member function query() on a non-object in /home/bfp111/public_html/carmarket.php on line 31 I hope all the lines you need are there Thanks Regards Link to comment https://forums.phpfreaks.com/topic/99368-solved-fatal-error-call-to-a-member-function-query-error-please-read/ Share on other sites More sharing options...
trq Posted April 3, 2008 Share Posted April 3, 2008 $db is not defined anywhere within your function. Where is it defined? Link to comment https://forums.phpfreaks.com/topic/99368-solved-fatal-error-call-to-a-member-function-query-error-please-read/#findComment-508399 Share on other sites More sharing options...
rhodesa Posted April 3, 2008 Share Posted April 3, 2008 I assume you declare $db outside the function. Add it to the list of globals: global $ir,$c,$userid,$h,$db; Link to comment https://forums.phpfreaks.com/topic/99368-solved-fatal-error-call-to-a-member-function-query-error-please-read/#findComment-508401 Share on other sites More sharing options...
trq Posted April 3, 2008 Share Posted April 3, 2008 globals within functions are an absolutely terrible idea. Kinda defates the purpose of functions. Link to comment https://forums.phpfreaks.com/topic/99368-solved-fatal-error-call-to-a-member-function-query-error-please-read/#findComment-508403 Share on other sites More sharing options...
juelpatwary Posted April 3, 2008 Author Share Posted April 3, 2008 ty, Were do i add it to again? Im kinda new i think i should add it to globals.php << Thats runs that database info and that i think Link to comment https://forums.phpfreaks.com/topic/99368-solved-fatal-error-call-to-a-member-function-query-error-please-read/#findComment-508404 Share on other sites More sharing options...
juelpatwary Posted April 3, 2008 Author Share Posted April 3, 2008 Were do i put global $ir,$c,$userid,$h,$db; Again? Im kinda new to php erroring lol Link to comment https://forums.phpfreaks.com/topic/99368-solved-fatal-error-call-to-a-member-function-query-error-please-read/#findComment-508408 Share on other sites More sharing options...
rhodesa Posted April 3, 2008 Share Posted April 3, 2008 Line 27...the first line of code inside your function Link to comment https://forums.phpfreaks.com/topic/99368-solved-fatal-error-call-to-a-member-function-query-error-please-read/#findComment-508413 Share on other sites More sharing options...
juelpatwary Posted April 3, 2008 Author Share Posted April 3, 2008 YEah, I got it now thanks sorted... Thanks for your help i was about to post but you posted before me Loooool Anyway thanks again Link to comment https://forums.phpfreaks.com/topic/99368-solved-fatal-error-call-to-a-member-function-query-error-please-read/#findComment-508415 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.