Page 1 of 1
Inconsistent MySQL results from PHP script
Posted: Mon Jul 20, 2009 12:01 am
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
Re: Inconsistent MySQL results from PHP script
Posted: Mon Jul 20, 2009 2:03 am
by sanju
Print the query in your php code and see how the query builds in the code..
Regards
Sanju
Re: Inconsistent MySQL results from PHP script
Posted: Mon Jul 20, 2009 4:31 pm
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.
Re: Inconsistent MySQL results from PHP script
Posted: Mon Jul 20, 2009 10:47 pm
by raptor354
Yep.
Re: Inconsistent MySQL results from PHP script
Posted: Mon Jul 20, 2009 11:02 pm
by Benjamin
Post the entire script please.
Re: Inconsistent MySQL results from PHP script
Posted: Tue Jul 21, 2009 1:17 am
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