n14charlie Posted July 26, 2009 Share Posted July 26, 2009 I want to increment a value in the table (which is 0 at the begining) but everytime I do query on the table it returns 0 even after I incremented it. $query = mysql_query(" SELECT * from session".$session."_".$username." WHERE Auction_Num = $highest_Num" ,$connection); $result = mysql_fetch_array($query); $bid_hover_num = $result['Bid_Hover_Windows']; $bid_hover_num = (int)$bid_hover_num + 2; mysql_query(" UPDATE session".$session."_".$username." SET Bid_Hover_Windows = $bid_hover_num WHERE Auction_Num = $highest_num" ,$connection); the value just stays "2" all the time which leads me to thing Im getting "0" from the table all the time. I replaced the "+2" with a "+rand(1,1000)" and it just replaces the zero with the random value. Quote Link to comment https://forums.phpfreaks.com/topic/167487-solved-query-returns-old-value/ Share on other sites More sharing options...
GingerRobot Posted July 26, 2009 Share Posted July 26, 2009 Well, why don't you try debugging your update query? Or, indeed, echoing the value from the database before you do anything to it? I'll direct you to the database errors section of a tutorial i wrote: http://www.phpfreaks.com/tutorial/debugging-a-beginners-guide On the other hand, you don't need to select something from a database in order to increment it. You can do the following instead: UPDATE yourtable SET foobar=foobar + 2 WHERE ... Quote Link to comment https://forums.phpfreaks.com/topic/167487-solved-query-returns-old-value/#findComment-883179 Share on other sites More sharing options...
n14charlie Posted July 26, 2009 Author Share Posted July 26, 2009 Well, why don't you try debugging your update query? Or, indeed, echoing the value from the database before you do anything to it? I'll direct you to the database errors section of a tutorial i wrote: http://www.phpfreaks.com/tutorial/debugging-a-beginners-guide On the other hand, you don't need to select something from a database in order to increment it. You can do the following instead: UPDATE yourtable SET foobar=foobar + 2 WHERE ... well that worked, I have no idea why my way was wrong though :/ thank you for the help Quote Link to comment https://forums.phpfreaks.com/topic/167487-solved-query-returns-old-value/#findComment-883184 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.