Adaaam Posted July 15, 2015 Share Posted July 15, 2015 Hello, Well this is embarrasing. Can anyone tell me why the $_SESSION['values'] array keeps getting overwritten every time I try adding a new value to it? Instead of the new value being added to the end of the array, the whole array gets overwritten with the new value and I don't know why? <?php session_start(); $_SESSION['values'] = array(); if (isset($_POST['value'])) { $_SESSION['values'][] = $_POST['value']; } var_dump($_SESSION['values']) . '<br>'; ?> <html> <head> <title>Test</title> </head> <body> <form method="post"> <input type="text" name="value"> <input type="submit" name="submit" value="submit"> </form> </body> </html> Hope this makes sense, I really don't know why it's not working. Thanks, Adam Quote Link to comment Share on other sites More sharing options...
Solution fastsol Posted July 15, 2015 Solution Share Posted July 15, 2015 Simple, you're clearing it on the 3rd line of the script everytime the page loads $_SESSION['values'] = array(); This would be more appropriate. if(!isset($_SESSION['values'])) { $_SESSION['values'] = array(); } 1 Quote Link to comment Share on other sites More sharing options...
Adaaam Posted July 15, 2015 Author Share Posted July 15, 2015 I knew it would be something stupid. Thanks for pointing that out. Quote Link to comment 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.