homepage Welcome to WebmasterWorld Guest from 54.161.175.231
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Is there a better way to write this line?
It does the job sometimes Yes sometimes No!
smagdy




msg:1265766
 7:52 pm on Jul 3, 2005 (gmt 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

 

moltar




msg:1265767
 8:07 pm on Jul 3, 2005 (gmt 0)

This is the correct way. Are you sure that the problem is not with multiple submits?

smagdy




msg:1265768
 8:19 pm on Jul 3, 2005 (gmt 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!

moltar




msg:1265769
 8:33 pm on Jul 3, 2005 (gmt 0)

Could you post a bigger chunk of code? I think there could be a problem with a conditional loop or something similar...

copongcopong




msg:1265770
 4:27 am on Jul 4, 2005 (gmt 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());

}

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved