Inconsistent MySQL results from PHP script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
raptor354
Forum Newbie
Posts: 13
Joined: Tue Jun 16, 2009 3:21 pm

Inconsistent MySQL results from PHP script

Post by raptor354 »

I am doing a MySQL query from a php script, but it doesn't seem to always come back with a result. I'm not sure if it's PHP or MySQL to blame, but I can't get anywhere relative to this problem.

The query that gets done is:

Code: Select all

UPDATE Member SET LastActivity='2009-07-19 21:09:19' WHERE MemberId='cb40659e-cd4c-1a74-059f-23f22c2928b2' LIMIT 1
The above query works when directly done to the database.

The script that formulates the query is:

Code: Select all

$userid = $_REQUEST['s27userid']; 
$date = date("Y-m-d H:i:s"); 
$qry="UPDATE Member SET LastActivity='" . $date . "' WHERE MemberId='" . $userid . "' LIMIT 1"; 
mysql_query($qry);
Is there an obvious reason why this wouldn't work? What am I doing wrong?

Raptor354
User avatar
sanju
Forum Commoner
Posts: 65
Joined: Sat Jun 21, 2008 2:15 am
Location: Kochi, India

Re: Inconsistent MySQL results from PHP script

Post by sanju »

Print the query in your php code and see how the query builds in the code..



Regards
Sanju
raptor354
Forum Newbie
Posts: 13
Joined: Tue Jun 16, 2009 3:21 pm

Re: Inconsistent MySQL results from PHP script

Post by raptor354 »

@sanju: That's how I got the compiled query. Copied straight off of a demo page I have.

@McInfo: I stripped a lot of that because I thought I had it working a few days ago. I also have a demo page. I'm aware of the MySQL Injection vulnerability and have implemented it everywhere else. I'm just trying to make this work. Yes, s27userid gets through. As I said to sanju, that's the compiled query that you see.

When I do mysql_query("UPDATE Member SET LastActivity='2009-07-19 21:09:19' WHERE MemberId='cb40659e-cd4c-1a74-059f-23f22c2928b2' LIMIT 1"), it works perfectly. When I go through the compilation process, it doesn't seem to actually do anything.
raptor354
Forum Newbie
Posts: 13
Joined: Tue Jun 16, 2009 3:21 pm

Re: Inconsistent MySQL results from PHP script

Post by raptor354 »

Yep.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Inconsistent MySQL results from PHP script

Post by Benjamin »

Post the entire script please.
raptor354
Forum Newbie
Posts: 13
Joined: Tue Jun 16, 2009 3:21 pm

Re: Inconsistent MySQL results from PHP script

Post by raptor354 »

I appreciate your time, folks, but I had an epiphany a few minutes ago.

In a script that calls a function (it determines if a user is still logged in), I set a cookie but then immediately request it's value in the function. It seems as though I outran the internet because when I hard-coded it, it worked, but when I let it run in a "full-auto" configuration, it failed every time.

The fix: let the code that calls the function to pass in the userid. To fix the problem in the offending script with the problem, I grabbed the data from an earlier call. Everything works like it should now.

Just wanted to tell all the other noobs (like me) how to fix this kind of problem.

Thanks again,

Raptor354
Post Reply