Welcome to WebmasterWorld Guest from 54.158.36.59

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)

10+ Year Member



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 Jul 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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

10+ Year Member



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 Jul 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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 Jul 4, 2005 (gmt 0)

10+ Year Member



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());

}

 

Featured Threads

Hot Threads This Week

Hot Threads This Month