homepage Welcome to WebmasterWorld Guest from 23.23.22.200
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Trouble with 'Access denied' with PHP/MySQL
bit of a mystery.....
nwilson




msg:1263407
 3:56 pm on May 11, 2002 (gmt 0)

Hi everyone, I'm having real difficulties :-(
the function below works just fine on a few calls to MySQL within the script but gets access denied when used in change_password() which I've also included at the end.

Any insight into this irregularity would be much appreciated :-)

function _db_connect() {

$this->link_id=@mysql_connect($this->host, $this->user,
$this->pass) or die("Could not connect to database");

if(!$this->link_id) {
return FALSE;
}

$db=@mysql_select_db($this->db) or die ("can't select db");
return TRUE;
}

and here is the function it fails in....

function change_password($email, $new_password) {

$new_password=md5($new_password); // encryption

$qry="UPDATE $this->table SET pass = '$new_password' ";
$qry.="WHERE email = '$email'";

if(!$this->_db_connect()) {
return FALSE;
}

if(!($result=mysql_query($qry, $this->link_id))) {
return FALSE;
} else {

if(mysql_affected_rows()==0) {
return FALSE;
} else {
$this->set_pass($new_password);
}

}

return TRUE;

}

 

sugarkane




msg:1263408
 8:32 pm on May 12, 2002 (gmt 0)

Are you only getting the error when you try to do an UPDATE or INSERT? Could be a privileges problem if you can do selects without any problems...

Lisa




msg:1263409
 8:40 pm on May 12, 2002 (gmt 0)

SIDE NOTE: I would recommend not using underlines to start function names. underlines in the first character are generally resevered for functions declared by the language maker and not users.

Now to the program....

$this->table is not set.
Is this inside a class? You may want to include the whole class. Looks like I am missing code here.

nwilson




msg:1263410
 8:44 pm on May 12, 2002 (gmt 0)

No, not that. It does these other types of operations in other areas of the site just fine.

I've kinda worked out whats causing it but not why....

It seems that passing the object in a session and trying to use the db methods on a page other than the one the object was instantiated on messes it up.

God knows why....

But just starting a new instance of the object and making calls to the db methods with that object works fine.

There is no reason I can see that would make it 'deny access' like this but a solution has been reached anyway :-)

Cheers

Nick

nwilson




msg:1263411
 8:49 pm on May 12, 2002 (gmt 0)

Lisa

as for the _underlines. Not so, in classes it is a way of seperating private from public methods and other than being a tidy convention has no effect on the code.

as for $this->table not being set: firstly the problem does not occur here. it is 'Access denied' by mysql when the program attempts to conect, not query.

It is indeed in a class and naturally the whole class is included. (otherwise how would I access these methods?)

Anyway, hope my last post makes sense :-)

Cheers

Nick

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved