BoGFx Posted November 17, 2009 Posted November 17, 2009 Hi, sorry for asking, but I have blow my mind out on google and can not seem to figure this out. I get the following error Fatal error: Call to a member function query() on a non-object in /home/cagedmaf/public_html/register.php on line 200 if(file_exists('ipbans/'.$IP)) { die("[b]<font color=red size=+1>Your IP has been banned, there is no way around this.</font>[/b]</body></html>"); } if($_POST['username']) { if($set['regcap_on']) { if(!$_SESSION['captcha'] or $_SESSION['captcha'] != $_POST['captcha']) { unset($_SESSION['captcha']); die("Captcha Test Failed >[url='register.php']Back[/url]"); } unset($_SESSION['captcha']); } if(!valid_email($_POST['email'])) { die("Sorry, the email is invalid. >[url='register.php']Back[/url]"); } if(strlen($_POST['username']) < 4) { die("Sorry, the username is too short. >[url='register.php']Back[/url]"); } $sm=100; if($_POST['promo'] == "Your Promo Code Here") { $sm+=100; } $username=$_POST['username']; $username=str_replace(array("<", ">"), array("<", ">"), $username); $usernameck=$db->query("SELECT * FROM users WHERE username='{$username}' OR login_name='{$username}'"); $q2=$db->query("SELECT * FROM users WHERE email='{$_POST['email']}'"); if($db->num_rows($usernameck)) { print "Username already in use. Choose another. >[url='register.php']Back[/url]"; } else if($db->num_rows($q2)) { print "E-Mail already in use. Choose another. >[url='register.php']Back[/url]"; } else if($_POST['password'] != $_POST['cpassword']) { print "The passwords did not match, go back and try again. >[url='register.php']Back[/url]"; } else { $_POST['ref'] = abs((int) $_POST['ref']); $IP = ($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']; $q=$db->query("SELECT * FROM users WHERE lastip='$IP' AND userid={$_POST['ref']}"); if($db->num_rows($q)) { die("No creating referral multies. Bad dog. >[url='register.php']Back[/url]"); } if($_POST['ref']) { $q=$db->query("SELECT * FROM users WHERE userid={$_POST['ref']}"); $r=$db->fetch_row($q); } $db->query("INSERT INTO users (username, login_name, userpass, level, money, crystals, donatordays, user_level, energy, maxenergy, will, maxwill, brave, maxbrave, hp, maxhp, location, gender, signedup, email, bankmoney, lastip, lastip_signup) VALUES( '{$username}', '{$username}', md5('{$_POST['password']}'), 1, $sm, 0, 0, 1, 12, 12, 100, 100, 5, 5, 100, 100, 1, '{$_POST['gender']}', unix_timestamp(), '{$_POST['email']}', -1, '$IP', '$IP')"); $i=$db->insert_id(); $db->query("INSERT INTO userstats VALUES($i, 10, 10, 10, 10, 10)"); if($_POST['ref']) { require "global_func.php"; $db->query("UPDATE users SET crystals=crystals+2 WHERE userid={$_POST['ref']}"); event_add($_POST['ref'],"For refering $username to the game, you have earnt 2 valuable crystals!",$c); $db->query("INSERT INTO referals VALUES('', {$_POST['ref']}, $i, unix_timestamp(),'{$r['lastip']}','$IP')"); } print "You have signed up, enjoy the game. > [url='login.php']Login[/url]"; } } else { if($set['regcap_on']) { $chars="123456789abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!?\\/%^"; $len=strlen($chars); $_SESSION['captcha']=""; for($i=0;$i<6;$i++) $_SESSION['captcha'].=$chars[rand(0, $len - 1)]; } Line 200 is Line 34. Thanks a bunch. I bet it is something simple and I am just stupid. Quote
Gucci Mane Posted November 18, 2009 Posted November 18, 2009 Try this: if(file_exists('ipbans/'.$IP)) { die("[b]<font color=red size=+1>Your IP has been banned, there is no way around this.</font>[/b]</body></html>"); } if($_POST['username']) { if($set['regcap_on']) { if(!$_SESSION['captcha'] or $_SESSION['captcha'] != $_POST['captcha']) { unset($_SESSION['captcha']); die("Captcha Test Failed >[url='register.php']Back[/url]"); } unset($_SESSION['captcha']); } if(!valid_email($_POST['email'])) { die("Sorry, the email is invalid. >[url='register.php']Back[/url]"); } if(strlen($_POST['username']) < 4) { die("Sorry, the username is too short. >[url='register.php']Back[/url]"); } $sm=100; if($_POST['promo'] == "Your Promo Code Here") { $sm+=100; } $username=$_POST['username']; $username=str_replace(array("<", ">"), array("<", ">"), $username); $username=$db->query("SELECT * FROM users WHERE username='{$username}' OR login_name='{$username}'"); $q2=$db->query("SELECT * FROM users WHERE email='{$_POST['email']}'"); if($db->num_rows($usernameck)) { print "Username already in use. Choose another. >[url='register.php']Back[/url]"; } else if($db->num_rows($q2)) { print "E-Mail already in use. Choose another. >[url='register.php']Back[/url]"; } else if($_POST['password'] != $_POST['cpassword']) { print "The passwords did not match, go back and try again. >[url='register.php']Back[/url]"; } else { $_POST['ref'] = abs((int) $_POST['ref']); $IP = ($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']; $q=$db->query("SELECT * FROM users WHERE lastip='$IP' AND userid={$_POST['ref']}"); if($db->num_rows($q)) { die("No creating referral multies. Bad dog. >[url='register.php']Back[/url]"); } if($_POST['ref']) { $q=$db->query("SELECT * FROM users WHERE userid={$_POST['ref']}"); $r=$db->fetch_row($q); } $db->query("INSERT INTO users (username, login_name, userpass, level, money, crystals, donatordays, user_level, energy, maxenergy, will, maxwill, brave, maxbrave, hp, maxhp, location, gender, signedup, email, bankmoney, lastip, lastip_signup) VALUES( '{$username}', '{$username}', md5('{$_POST['password']}'), 1, $sm, 0, 0, 1, 12, 12, 100, 100, 5, 5, 100, 100, 1, '{$_POST['gender']}', unix_timestamp(), '{$_POST['email']}', -1, '$IP', '$IP')"); $i=$db->insert_id(); $db->query("INSERT INTO userstats VALUES($i, 10, 10, 10, 10, 10)"); if($_POST['ref']) { require "global_func.php"; $db->query("UPDATE users SET crystals=crystals+2 WHERE userid={$_POST['ref']}"); event_add($_POST['ref'],"For refering $username to the game, you have earnt 2 valuable crystals!",$c); $db->query("INSERT INTO referals VALUES('', {$_POST['ref']}, $i, unix_timestamp(),'{$r['lastip']}','$IP')"); } print "You have signed up, enjoy the game. > [url='login.php']Login[/url]"; } } else { if($set['regcap_on']) { $chars="123456789abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!?\\/%^"; $len=strlen($chars); $_SESSION['captcha']=""; for($i=0;$i<6;$i++) $_SESSION['captcha'].=$chars[rand(0, $len - 1)]; } Quote
Danny696 Posted November 18, 2009 Posted November 18, 2009 Two things, $IP = ($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']; Is insecure. and whats differnt? Quote
CrazyT Posted November 18, 2009 Posted November 18, 2009 That error.. Just global $db; or... $db = new Database(); Quote
seanybob Posted November 19, 2009 Posted November 19, 2009 That error.. Just global $db; or... $db = new Database(); Yup, he's right. The code you posted above is probably in some function or object that has it's own scope, separate from your main php script. So, at the beginning of this function/object, redeclare the $db variable. function myfunc() { global $db; code here } Quote
Zero-Affect Posted November 19, 2009 Posted November 19, 2009 That error.. Just global $db; or... $db = new Database(); was totally just going to say that lol Quote
BoGFx Posted November 19, 2009 Author Posted November 19, 2009 That error.. Just global $db; or... $db = new Database(); was totally just going to say that lol Ahh, I see where I messed up. When I tried that, it would not define the DB either - I didn't have any of the CONFIG stuff the the entire script, ha. All fixed. THANKS! Btw, I secured it too, so it's all good :D Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.