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.
– lpFranz
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
– Guilherme Bartasson
The following is the folder structure: https://snag.gy/xJFU19.jpg
– Guilherme Bartasson
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.– lpFranz
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).
– Guilherme Bartasson
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.– lpFranz
Is there any way I can get around this by just saving the data in the database when Submit is pressed?
– Guilherme Bartasson