Form action parameter opening php script

Asked

Viewed 41 times

0

My problem is relatively simple, I have a form and I need that: when clicking the Submit button the data is passed to a php file (referenced in the action parameter of the form) that will save the data in a database. However when I click the Submit button the form displays the code of my php file (I’m using an external file for php). The expected result would be that nothing was displayed and the data was saved in the database, as I do this?

  • Apparently your PHP file is not on a PHP-supported server, a good option is xampp https://www.apachefriends.org/pt_br/index.html.

  • I am using xampp, all the files are in the htdocs folder inside another folder. In this folder is the html file and in another folder is my php file

  • The following is the folder structure: https://snag.gy/xJFU19.jpg

  • How are you accessing your html file? for PHP to work, you should run html using HTTP and not File://, in other words, you should not double-click your html, you should open your browser, type in the address localhost and browse to your HTML file.

  • Right, I navigated the localhost, but when I gave Submit in the form the following page was shown: https://snag.gy/hpHoPL.jpg. I know my code was an echo and it should happen anyway, but if it was a query in a database another window would open? Or would the server remain in my html file? (in case what I want).

  • Apparently this is the default behavior, the form action redirects to your PHP file, so anyway, you can give a redirect to go back to your page, you can use the header("location:$redirect"); for that reason.

  • Is there any way I can get around this by just saving the data in the database when Submit is pressed?

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.