Welcome to WebmasterWorld Guest from 54.166.48.3

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Is there a better way to write this line?

It does the job sometimes Yes sometimes No!

     
7:52 pm on Jul 3, 2005 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 21, 2004
posts:418
votes: 0


Hi,

I just want to increment a simple INT field with 1

mysql_query("update brands set views=(views+1) where id=".$mycat[0]."") or die(mysql_error());

with same steps it sometimes increment 1 as it should and other time it increments 2 or 3 or 4.

so is there better way to do the increment..?

any help is appreciated.
Thanks in advance

8:07 pm on July 3, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 18, 2003
posts:1925
votes: 0


This is the correct way. Are you sure that the problem is not with multiple submits?
8:19 pm on July 3, 2005 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 21, 2004
posts:418
votes: 0


yes am very suree and if it was multiple then it should have add same amount all the time.. but most of the time its working right then suddenly add more and with some tracing i found that it adds those amounts just exactly after that line

for ex: the number is DB is now 1 then after the update query it becomes 3 or 4

very strange!

8:33 pm on July 3, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 18, 2003
posts:1925
votes: 0


Could you post a bigger chunk of code? I think there could be a problem with a conditional loop or something similar...
4:27 am on July 4, 2005 (gmt 0)

Full Member

10+ Year Member

joined:May 9, 2002
posts:241
votes: 0


try to put the code in a conditional statement for the post to be sure that it won't be executed if not intended ... e.g.

if(isset($_POST['submit'])){

mysql_query("update brands set views=(views+1) where id=".$mycat[0]."") or die(mysql_error());

}