[PHP] Classes and Functions and If's (Problems Again)
Hi everyone, i have some code that proccesses a login form. i have an object $DB which works only in SOME areas, this is the code: ?php require_once(Include.php); global $DB; $Username= $_REQUEST['Username']; $Password= $_REQUEST['Password']; $SQL= SELECT * FROM members WHERE Username='$Username' AND Password='$Password'; ; $DB-Query($SQL); $UserInfo=$DB-QueryInfo(Array); if($UserInfo==0) $Login=FALSE; else $Login=TRUE; //Make Sure the user is not a duplicate user trying to log in again if($Login=TRUE) { global $DB; $RL=__; $LoginD=__; $ID=$UserInfo['ID']; echo $ID; $DB=membersp; $SQL=SELECT ID FROM membersonline WHERE ID='$ID' ; $DB-Query($SQL); $CheckFD=$Result; if($CheckFD!=0) $LoginD=TRUE; else $LoginD=FALSE; if($LoginD==TRUE) { $RL=TRUE; //code to allow user onto next page without interfering with the security measures $DB=membersp; $SQL=SELECT * FROM membersonline WHERE ID=$ID; DBConnect($DB,$SQL); $Slide=$Result; $NextCode=$Slide['NextCode']; } if($LoginD==FALSE) { // Now we start to create and write the data that will let other pages know if the user is logged in or not $Seed= rand(); srand($Seed); $NextCode= rand(); $PageNumber=1; $DB=membersp; $SQL=INSERT INTO MembersOnline (ID, Seed, PageNumber, NextCode) VALUES ('{$ID}', '$Seed', '$PageNumber', '$NextCode') ; DBConnect($DB,$SQL); } } ? !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd; html xmlns=http://www.w3.org/1999/xhtml; head ?php Init(2); ? title/title /head body ?php if($Login==FALSE) echo(p class='error'Login failed, wrong username and/or password please a href='Login.php'Try Again/a or a href=' Register.php'Register/a/p); if(@$RL==TRUE) echo(p class='error'You have already logged in, click a href='Projects.php?Code={$NextCode}'Here/a to go on/p); ? /body /html i get an error saying: *Fatal error*: Call to a member function Query() on a non-object in * D:\Apache\Apache(re)\Apache2\htdocs\LoginP.php* on line *21* but before line 21 i use $DB and it works fine, but line 21 is a problem, any help appreciated
Re: [PHP] Classes and Functions and If's (Problems Again)
On Thu, 2005-11-03 at 18:37 -0500, Unknown Unknown wrote: Hi everyone, i have some code that proccesses a login form. i have an object $DB which works only in SOME areas, this is the code: ?php require_once(Include.php); global $DB; There is no need to global $DB here. You are already in the global scope. $Username= $_REQUEST['Username']; $Password= $_REQUEST['Password']; $SQL= SELECT * FROM members WHERE Username='$Username' AND Password='$Password'; ; $DB-Query($SQL); $UserInfo=$DB-QueryInfo(Array); if($UserInfo==0) $Login=FALSE; else $Login=TRUE; Why aren't you using real boolean values here? //Make Sure the user is not a duplicate user trying to log in again if($Login=TRUE) { global $DB; Again, no need to global $DB. You are still in the global scope. $RL=__; $LoginD=__; $ID=$UserInfo['ID']; echo $ID; $DB=membersp; Here is your problem. You just replaced the $DB object with a string. Maybe you meant to set a property on the $DB object? I think you may need to do some reading on OOP, perhaps start at http://php.net/oop for PHP4 or http://php.net/oop5 for PHP5. -- Jasper Bryant-Greene General Manager Album Limited e: [EMAIL PROTECTED] w: http://www.album.co.nz/ b: http://jbg.name/ p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303 a: PO Box 579, Christchurch 8015, New Zealand -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Classes and Functions and If's (Problems Again)
On 11/4/05, Unknown Unknown [EMAIL PROTECTED] wrote: Hi everyone, i have some code that proccesses a login form. i have an object $DB which works only in SOME areas, this is the code: [...] $DB=membersp; $SQL=SELECT ID FROM membersonline WHERE ID='$ID' ; $DB-Query($SQL); [...] i get an error saying: *Fatal error*: Call to a member function Query() on a non-object in * D:\Apache\Apache(re)\Apache2\htdocs\LoginP.php* on line *21* but before line 21 i use $DB and it works fine, but line 21 is a problem, any help appreciated You've not indicated which is line 21, but I presume it's the bit shortly after you assigned a string to $DB. A string is not an object, hence the error message. -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php