Home > Back-end >  "POST /test.php" Error (404): "Not found"
"POST /test.php" Error (404): "Not found"

Time:04-04

Warning: I'm a total newbie to php.

I followed a tutorial for writing a php script that takes input from a sign-up page (html) and stores it in a database (mysql/Wamp). But when I tried to test it to see if everything's working, I get this:

"GET /tester.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.60 Safari/537.36"
"POST /test.php" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.60 Safari/537.36"
"POST /test.php" Error (404): "Not found"

I don't understand why it can't find test.php. I have it referenced in the html, as you can see:

<!DOCTYPE HTML>
<html>
<head>
  <title>Register Form</title>
</head>
<body>
 <form action="/test.php" method="POST">   <--- php reference
  <table>
   <tr>
    <td>Name :</td>
    <td><input type="text" name="username" required></td>
   </tr>
   <tr>
    <td>Password :</td>
    <td><input type="password" name="password" required></td>
   </tr>
   <tr>
    <td><input type="submit" value="Submit" name="submit"></td>
   </tr>
  </table>
 </form>
</body>
</html>

A straight up solution would be great, but ways to find out what I need to google would also work.

EDIT1:

Here's my file structure. It's very simple.

File structure

CodePudding user response:

the '/' in your action will set the path back to root, so if your form and php are in a directory http://eaxmple.com/this/is/a/path/tester.html your form action will return to http://eaxmple.com/test.php

if you want them in the same directory change action='test.php' or to the path that the file resides :)

but without seeing your file structure I'm not 100%

<!DOCTYPE HTML>
<html>
<head>
  <title>Register Form</title>
</head>
<body>
 <form action="test.php" method="POST">   <--- php reference
  <table>
   <tr>
    <td>Name :</td>
    <td><input type="text" name="username" required></td>
   </tr>
   <tr>
    <td>Password :</td>
    <td><input type="password" name="password" required></td>
   </tr>
   <tr>
    <td><input type="submit" value="Submit" name="submit"></td>
   </tr>
  </table>
 </form>
</body>
</html>

CodePudding user response:

You have run it on a server not locally . Try to configure your apache server locally if you are not working on a server because php scripts runs only on a server environment.

CodePudding user response:

remove '/' <form action="/test.php" method="POST"> ---> <form action="test.php" method="POST">

maybe can help you, thank you.

  • Related