Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Shane Meikle
Shane Meikle
13,188 Points

How to erase previously output echo command on new form submit?

I am currently playing around with a project and it is outputting content based on what the user selected on the form. The form is broken into categories to make it easier to navigate and each category has its own function tied to ouputting an echo command.

The problem I am currently running into is:

User submits form once, and information is echoed to screen, User submits form again and then screens outputs the info from previous echo plus information from the new echo.

What I am wanting to do is clear the previous echo before showing the new echo.

Any suggestions?

3 Answers

It sounds like you're trying to kill the $_POST variable in between submissions. You could save the incoming $_POST data into a new variable and work with that variable in your script.

You could then unset the $_POST variable ready for a new submission.

Another method is to use sessions - this resource might give you some inspiration.

Lot's of stack overflow answers by searching "unset $_POST variable"

Hope this helps!

Chris Malcolm
Chris Malcolm
2,909 Points

could you possible post a snippet of your code?

to troubleshoot, though, and this is a long shot, but if this is being done with standard POST requests, perhaps you are setting an input field (lets say 'name') for your first request..and when submitted it sets the value for that input field ('name') or another field in your form on new page reload . This would mean that when you submit your second request (ex. 'email'). This would mean $_POST['name'] + $_POST['email'] exists.

Shane Meikle
Shane Meikle
13,188 Points

Thank you all for your responses, but I found the issue.

In my form, I created a function to default a textbox to what a user may have selected. That value was passed along with the new select value, which then showed the two values. I forgot to add the '&' reference indicator to the function argument.