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
Archy
Forum Contributor
Posts: 129 Joined: Fri Jun 18, 2004 2:25 pm
Location: USA
Post
by Archy » Mon Jan 17, 2005 5:49 am
I have a query that updates a database when a user displays a banner on his/her site. Below is the code I am using.
Code: Select all
<?PHP
header("Content-type: image/gif");
include('connectToDatabase.php'); // Connect to database
$sql = "UPDATE `table` SET `hits`=`hits`+1 WHERE `activity`=1 && `number`='$num'";
$rs = mysql_query($sql) or die(mysql_error());
readfile("http://www.site.com/image.gif");
?>
However, it seems to disregard && `activity`=1, and so it updates the database even when activity does not equal 1.
Does anybody know if this is because of the content type, and a way around it?
Thanks.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Jan 17, 2005 7:43 am
try this:
Code: Select all
UPDATE `table` SET `hits`=`hits`+1 WHERE `activity` = '1' AND `number`='$num'
Archy
Forum Contributor
Posts: 129 Joined: Fri Jun 18, 2004 2:25 pm
Location: USA
Post
by Archy » Mon Jan 17, 2005 8:16 am
Unfortunatly that did not work.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Jan 17, 2005 8:20 am
have you tried using this query inside phpMyAdmin?
Archy
Forum Contributor
Posts: 129 Joined: Fri Jun 18, 2004 2:25 pm
Location: USA
Post
by Archy » Mon Jan 17, 2005 8:38 am
Yes, the query works fine using phpMyAdmin.
Affected rows: 1 (Query took 0.0012 sec)
SQL-query:
UPDATE `table` SET `hits` = `hits` +1 WHERE `activity` = '1' AND `number` = '406762652'
I first changed the `activity` to 0, and it did not update, and then I changed it to 1, and it updated successfully; it isnt the query that is wrong, and is why I thought it may have something to do with the content type of the page.
I added the content-type: text/html, and it still did not work.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Jan 17, 2005 8:43 am
hmmm
What about $num, are you sure that's coming in right? Because it looks like it requires register_globals to be on..
That's about the only thing left outstanding that I can see..
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Jan 17, 2005 8:47 am
are register_globals on?
Archy
Forum Contributor
Posts: 129 Joined: Fri Jun 18, 2004 2:25 pm
Location: USA
Post
by Archy » Mon Jan 17, 2005 8:53 am
How can I turn them on, I am not sure if they are on or off.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Jan 17, 2005 9:05 am
you can check via this:
Code: Select all
echo 'Register Globals are: ' . (ini_get('register_globals') == 1 ? '<b>ON</b>' : 'off');
It's better to avoid needing them on, since they are off by default these days like so:
Code: Select all
$num = (isset($_GETї'num']) && is_numeric($_GETї'num']) ? intval($_GETї'num']) : false);
if($num === false) die('you smell like poo');
// do your query
Archy
Forum Contributor
Posts: 129 Joined: Fri Jun 18, 2004 2:25 pm
Location: USA
Post
by Archy » Mon Jan 17, 2005 9:08 am
Register Globals are: ON
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Jan 17, 2005 9:17 am
hmm.. and you echo'd the query string to see that $num is getting in there okay?
I'm stumped now..
Archy
Forum Contributor
Posts: 129 Joined: Fri Jun 18, 2004 2:25 pm
Location: USA
Post
by Archy » Mon Jan 17, 2005 9:26 am
Hmm, if I go to the actual page which updates the code, it works correctly, it just doesnt seem to like going through the <img> tag.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Jan 17, 2005 9:28 am
the actual page, being the still with the header call? hmm interesting...