简体   繁体   中英

404 error when submitting form

I keep getting a 404 error when trying to submit this form. In my website directory i have a folder called mobile , which inside has forms.php and process.php .

The form is located on this page

http://localhost/mobile/forms.php?ft=0&id=2

here is the form

<form action='/mobile/process.php?o=9&ft=0' method='POST'>
//details
</form>

When i try to submit i get a 404 error, when it should go to http://localhost/mobile/process.php?o=9&ft=0 ? How do i fix this?

By looking at the URL's what I conclude is that both the php files are on the same page so change your action url from

<form action='/mobile/process.php?o=9&ft=0' method='POST'>

To

<form action='process.php?o=9&ft=0' method='POST'>

A forward slash before the mobile means it selects the folder from the root.. So you probably don't need that here.

Last but not the least, be sure the file names are proper, and also make sure the cases are same, because the file names are case sensitive.

Note: You may also get 404 error if you are using header('Location: xyz.php'); on the form processing page, for redirecting the user to some page after the form processes and you may encounter 404 because the page on which the script has redirected doesn't exist. so make sure that the URL is correct if you are using header()

Try changing

<form action='/mobile/process.php?o=9&ft=0' method='POST'>

to

<form action='process.php?o=9&ft=0' method='POST'>

Since they are in the same directory.

You can't pass a GET parameter in the form action.

In order to pass parameters, you will have to create a hidden input like :

<input type="hidden" name="o">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM