Is this the correct code for updating databases and increment count column by one? $query = "UPDATE 'downloads' SET 'count' = 'count' +1 WHERE 'ip' = '$_SERVER[REMOTE_ADDR]'"; PHP: I set my ip column to primary key, varchar(15), not null and my count column to int(11) and not null. when I run this code in php and check my phpmyadmin, nothing changes Thanks in advance
use this one, never use single quotes around column names $query = "UPDATE downloads SET count = count +1 WHERE ip = '{$_SERVER["REMOTE_ADDR"]}'"; Code (markup):
thanks but when I run the code my count column in phpmyadmin is still 0? You sure count +1 will work... When I run the code, the code will check my IP and increment count to 1, I run the code again increment count to 2 and so on.... Thanks
but isn't count column should store data... if not how can php use data from mysql if the count column not updated. I get the +1 from here: http://www.webdeveloper.com/forum/showpost.php?p=611797&postcount=2 http://www.webmasterworld.com/databases_sql_mysql/3720902.htm isn't my count should increment to 1... sorry if I don't understand your answer... thanks
mwasif is saying that you have to run the code in PHP first and then check it in phpmyadmin. I imagine that is what you are doing but if you just want to enter a query directly in phpmyadmin you can run this to verify that it works: UPDATE downloads SET count = count +1 WHERE ip = '124.82.48.70'; Code (markup):
UPDATE downloads SET count = count +1 WHERE ip = '124.82.48.70'; Code (markup): The SQL query is valid and should work. Check if 'count' is int(11) and NULL is set to YES. Test it in phpMyAdmin.
Be sure to sanitise you input, the $_SERVER["REMOTE_ADDR"] part is untrusted user input. This means you are leaving yourself open to an SQL injection attack. Try a search on google for securityfocus sanitize $_SERVER["REMOTE_ADDR"] Sorry for the extra work I need to wait a bit before I can make links or something.