MySQL being executed upon page load

I’ll try to be as clear and concise as possible.

(I’ll preface this issue by saying my PHP isn’t excellent.)

I have a page called userlist.php in which admins are allowed access to change/update values in the database, whether it be email address, password, admin access, or being banned from the site. As of right now, I’m having an issue where one of those options available on userlist.php is being triggered when I load the page.

I’m using mysql_fetch_array to load all of the users on userlist.php. I’m not sure on the rules regarding posting code, so I’ll upload it here: http://pastebin.com/rf5gTUM4

Direct issue: Every time I load userlist.php lines 118-141 are executed without the form being submitted. Every user that is registered has their password changed, but not to any password I’ve chosen, just to some random password.

I believe this is directly caused by lines 124-126 not being above the header, but the problem is that I’m using a variable (np-$rowid) in the request which would be declared afterwords if I did move it and therefore it would be rendered invalid since you can’t call a variable before its been created.

If none of my explanation makes sense, just review my “direct issue” and reference it with my code.

I hope someone can help me.

Thanks,
awl19

may i suggest giving the password form an id and wrapping the div (lines 118 -141) in an if statement:

[php]

if(isset($_POST[‘myform’])) {
// code to run here is form submitted.
}[/php]
(or you could use the id of the submit button and check against that being submitted)

Hope that helps,
Red :wink:

Thanks, Redscouse! Your reply is much appreciated.

Here’s a link to the revised code: http://pastebin.com/uWkQtQzj (Line 122-125)

It worked in solving my issue (no more randomly generated passwords on page load), however it created a new problem. When I submit the change password form, nothing happens.

try change :
[php]if(isset($_POST[‘p-’.$rowid.’’]))[/php]
to:
[php]if(isset($_POST[‘np-’.$rowid.’’]))[/php]
let me know if that changes anything.
:slight_smile:

Derppp!

Having a fresh eye look at your code makes a world of difference.

You sir, are a gentleman and scholar. If I knew how to up your karma, I would.

Thanks! =)

no worries, glad i could help :wink:
Red.

Sponsor our Newsletter | Privacy Policy | Terms of Service