Jump to content

[SOLVED] Increasing variable by 1..


galvin

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/138808-solved-increasing-variable-by-1/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.