Help with Using POST Method in PHP for Form Submission

Hi PHP Help Community,

I’m trying to handle a form submission using the POST method in PHP, but I’m having some trouble. The form collects user data like name and email, and I’m trying to display the submitted information on a confirmation page after the user clicks “Submit.” However, when I try to access the data on the confirmation page, it’s empty.
The form submits just great, but when I go to load the confirm.php page, nothing shows up. Am I missing something with how the POST data is processed?

Also, as an aside, I’ve been studying various technologies, and I recently found the question what is chatgpt. I’m amazed at how AI can be used to support so many things, including development. Could anyone give some ideas on how things like ChatGPT could assist with PHP development?

Anything you have to offer or recommendations would be great!

Thank you in advance,
dejaco

In your form, all of your fields require a “name” attribute.

Let’s say you have an input like this:

<input type="text" name="firstname">

Then in your confirmation php page (this must be the one where the form is directly getting sent to… no redirect afterwards. You can set this in the action attribute of your form if it’s different to the script rendering the form)
you can access the submitted value via $_POST['firstname']

If this somehow doesn’t work for you, please share more details including full code of your form as well as the confirmation page script.

I used AI, but a word of caution: you still need to know how to code to avoid spaghetti or insecure code. I know firsthand that I’ve gotten angry at AI. I’m glad I was alone, as I’d look foolish talking to a computer screen. :rofl: It aids coding by simplifying repetitive tasks and assisting with refactoring to make code better, shorter, and less repetitive.

I have fixed so much faulty ChatGPT generated php for clients that I have stopped counting.

The issue with ChatGPT I guess is that it is getting a good amount of information from public sources, within which a good amount of wrong php code is included.

For coding, you would want to use a model that is very well trained for coding purposes instead of using a generic/universal one.

But also these more specialized ones won’t just write your program for you.

AI however is also a great assistant when it comes testing the code as well as (already mentioned) refactoring.

It can also help you doing version upgrades and find everything in your code that is affected by breaking changes i.e. when jumping from php 7.x to 8.x

It can help you do static code analysis for security reasons as well.

Sponsor our Newsletter | Privacy Policy | Terms of Service