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
Smackie
Forum Contributor
Posts: 302 Joined: Sat Jan 29, 2005 2:33 pm
Post
by Smackie » Fri Jun 17, 2005 9:10 pm
im not sure if this is right.. but i just want it where it will add one to the hits field in MySQL..
Code: Select all
mysql_query("e;INSERT INTO users (hits) VALUES('hits+1') WHERE userid = 'userid'"e;);
Thank you
Smackie
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Fri Jun 17, 2005 9:14 pm
Lose the quotes in your mathematics
Code: Select all
mysql_query("e;INSERT INTO `users` (`hits`) VALUES(`hits`+1) WHERE `userid` = 'userid'"e;);
Note: It's also good practise to get into the habit of using backticks to identify mysql database elements (feild names, table names etc) in your queries
Smackie
Forum Contributor
Posts: 302 Joined: Sat Jan 29, 2005 2:33 pm
Post
by Smackie » Fri Jun 17, 2005 9:21 pm
well for some reason its still not adding a anything to hits in mysql
so what am i doing wrong?
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Fri Jun 17, 2005 9:24 pm
Code: Select all
mysql_query("e;INSERT INTO `users` (`hits`) VALUES(`hits`+1) WHERE `userid` = 'userid'"e;) or die(mysql_error());
What's the error with the above? Sorry, i've had a few glasses
Smackie
Forum Contributor
Posts: 302 Joined: Sat Jan 29, 2005 2:33 pm
Post
by Smackie » Fri Jun 17, 2005 9:27 pm
im not getting any errors
here is the sql file
Code: Select all
CREATE TABLE `users` (
`userid` int(25) NOT NULL auto_increment,
`user_name` varchar(25) NOT NULL default '',
`email_address` varchar(155) NOT NULL default '',
`website` varchar(255) NOT NULL default '',
`msn` varchar(155) NOT NULL default '',
`aim` varchar(55) NOT NULL default '',
`yahoo` varchar(55) NOT NULL default '',
`about_me` text NOT NULL,
`password` varchar(55) NOT NULL default '',
`show_email` varchar(55) NOT NULL default '',
`show_msn` varchar(55) NOT NULL default '',
`show_aim` varchar(55) NOT NULL default '',
`show_yahoo` varchar(55) NOT NULL default '',
`rank` varchar(55) NOT NULL default '',
`user_level` enum('0','1','2','3','4','5') NOT NULL default '0',
`signup_date` datetime NOT NULL default '0000-00-00 00:00:00',
`last_login` datetime NOT NULL default '0000-00-00 00:00:00',
`online_time` datetime NOT NULL default '0000-00-00 00:00:00',
`activated` enum('0','1') NOT NULL default '0',
`hits` int(20) NOT NULL default '1',
PRIMARY KEY (`userid`),
FULLTEXT KEY `Website` (`website`)
) TYPE=MyISAM AUTO_INCREMENT=32
if that helps any
Skara
Forum Regular
Posts: 703 Joined: Sat Mar 12, 2005 7:13 pm
Location: US
Post
by Skara » Fri Jun 17, 2005 9:43 pm
you have to add an entire row when you INSERT something. You need to UPDATE.
Code: Select all
mysql_query("e;UPDATE `users` SET `hits`=`hits`+1 WHERE `userid` = 'userid' LIMIT 1"e;) or die(mysql_error());
Edit: woah. the code tag is broken. O.O
UPDATE `users` SET `hits`=`hits`+1 WHERE `userid` = 'userid' LIMIT 1
Smackie
Forum Contributor
Posts: 302 Joined: Sat Jan 29, 2005 2:33 pm
Post
by Smackie » Fri Jun 17, 2005 10:03 pm
what you mean code take is broken?
method_man
Forum Contributor
Posts: 257 Joined: Sat Mar 19, 2005 1:38 am
Post
by method_man » Fri Jun 17, 2005 10:34 pm
when u press the button it
Jim_Bo
Forum Contributor
Posts: 390 Joined: Sat Oct 02, 2004 3:04 pm
Post
by Jim_Bo » Sat Jun 18, 2005 12:12 am
Hi,
Code: Select all
mysql_query("UPDATE users SET hits=(hits+1) WHERE userid = '$userid'");
will do it.