Welcome to WebmasterWorld Guest from 54.147.20.131

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Trouble with 'Access denied' with PHP/MySQL

bit of a mystery.....

     

nwilson

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

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

WebmasterWorld Senior Member 10+ Year Member



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

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

WebmasterWorld Senior Member 10+ Year Member



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

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

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

 

Featured Threads

Hot Threads This Week

Hot Threads This Month