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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.