e1seix Posted November 3, 2007 Share Posted November 3, 2007 $p1=$row[pop]; $p2=1; $pop=($p1+$p2); mysql_query("UPDATE fragrances SET pop = '$pop' WHERE sku=$sku"); what's wrong with this code? the idea is that when a page loads on my website with the corresponding sku, the corresponding SET "pop" gets updated by 1 ie. the point is to show me which of my product sku's is most viewed by clients so i can base a top selling products page on. i did post this earlier today and now i can't find the topic at all to rehash it. anyway, any help would be appreciated. I'm more familiar with SELECT as oposed to UPDATE. what i have initially works and updates all products with "0" views to "1", but if the same page is revisited or refreshed it stays at "1". many thanks, Link to comment https://forums.phpfreaks.com/topic/75952-solved-update-function-query/ Share on other sites More sharing options...
Daukan Posted November 3, 2007 Share Posted November 3, 2007 You can add in the query itself and use single quote around $sku mysql_query("UPDATE fragrances SET pop=pop+1" WHERE sku='$sku'") Link to comment https://forums.phpfreaks.com/topic/75952-solved-update-function-query/#findComment-384427 Share on other sites More sharing options...
e1seix Posted November 3, 2007 Author Share Posted November 3, 2007 You can add in the query itself and use single quote around $sku mysql_query("UPDATE fragrances SET pop=pop+1" WHERE sku='$sku'") i'm guessing the additional " is out of place but even with taking that out i'm getting a t_string error Link to comment https://forums.phpfreaks.com/topic/75952-solved-update-function-query/#findComment-384436 Share on other sites More sharing options...
Daukan Posted November 3, 2007 Share Posted November 3, 2007 Yep I had an extra double quote in there sorry <?php mysql_query("UPDATE fragrances SET pop=pop+1 WHERE sku='$sku'") ?> Link to comment https://forums.phpfreaks.com/topic/75952-solved-update-function-query/#findComment-384438 Share on other sites More sharing options...
e1seix Posted November 3, 2007 Author Share Posted November 3, 2007 Yep I had an extra double quote in there sorry <?php mysql_query("UPDATE fragrances SET pop=pop+1 WHERE sku='$sku'") ?> it gives me a t_variable error. any ideas...? Link to comment https://forums.phpfreaks.com/topic/75952-solved-update-function-query/#findComment-384441 Share on other sites More sharing options...
Daukan Posted November 3, 2007 Share Posted November 3, 2007 Are you adding the ending semi colon -> ; Link to comment https://forums.phpfreaks.com/topic/75952-solved-update-function-query/#findComment-384443 Share on other sites More sharing options...
e1seix Posted November 3, 2007 Author Share Posted November 3, 2007 i am now and... it works. many thanks! Link to comment https://forums.phpfreaks.com/topic/75952-solved-update-function-query/#findComment-384444 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.