galvin Posted December 30, 2008 Share Posted December 30, 2008 Here is my simple code... if (!$_SESSION['take']) { $take = "1"; $_SESSION['take'] = $take; } else { $take = $_SESSION['take'] + 1; } imagejpeg($card1,"cards/" . $_SESSION['orderID'] . "card1" . $take . ".jpeg", 100); ...In the first part of the code, I see if $_SESSION['take'] is set yet. If it's the first visit, it is not set yet, so the variable $take is set to "1" and $_SESSION['take'] is set equal to $take. Then if the user returns to that page, $_SESSION['take'] IS now set, so $take becomes $_SESSION['take'] +1. (And in the part that creates the image, assume for example's sake that the $_SESSION['orderID'] = 44) This code is not working. It keeps creating the file with name of 44card11.jpg. That should be the first filename but it should change to 44card12.jpg the second time. And 44 card13 the third time, and so on. It seems like the line "$take = $_SESSION['take'] + 1;" is not working. Is my syntax right? If so, any ideas why this isn't working as intended? Quote Link to comment https://forums.phpfreaks.com/topic/138808-solved-increasing-variable-by-1/ Share on other sites More sharing options...
RussellReal Posted December 30, 2008 Share Posted December 30, 2008 change $take = $_SESSION['take'] + 1; to $_SESSION['take']++; Quote Link to comment https://forums.phpfreaks.com/topic/138808-solved-increasing-variable-by-1/#findComment-725825 Share on other sites More sharing options...
Jabop Posted December 30, 2008 Share Posted December 30, 2008 u culd do $_SESSION['temporary_variable'] = $_SESSION['take']; $_SESSION['take'] = $_SESSION['temporary_variable'] + 2; $_SESSION['take'] = $_SESSION['take'] - 1; pretty easy noob Quote Link to comment https://forums.phpfreaks.com/topic/138808-solved-increasing-variable-by-1/#findComment-725831 Share on other sites More sharing options...
galvin Posted December 30, 2008 Author Share Posted December 30, 2008 thanks russell! Quote Link to comment https://forums.phpfreaks.com/topic/138808-solved-increasing-variable-by-1/#findComment-725848 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.