Skip to main content
Participating Frequently
Mar 27, 2017 9:36 PM UTC
Answered

{"code":"MethodNotAllowedError","message":"POST is not allowed"} - PHP Submit Form

Hello,

I am learning to code with PHP and during my test I used the following code:

<!doctype html>

<html>

<head>

<meta charset="UTF-8">

<title>Untitled Document</title>

</head>

<body>

<?php

  if (isset($_POST['Submit'])) {

  // process form

  printf('User: %s

  Pass: %s

  Status: %s

  Comments: %s',

    $_POST['User'],

    $_POST['Pass'],

    $_POST['Status'],

    $_POST['Comments']);

  }

  ?>

<form method="post" action="">

  User: <input type="text" name="User"><br>

  Pass: <input type="password" name="Pass"><br>

  Status:

  <input type="radio" name="status">Single

  <input type="radio" name="status">Married

  <input type="radio" name="status">Divorced

  <input type="radio" name="status">Widowed<br>

  Comments:<textarea name="comments"></textarea><br>

  Submit:<input type="submit" name="submit" value="Submit">

  </form>

</body>

</html>

Dreamweaver didn't report any problems and when I tried to submit my form (localhost) it gave back the error on the title.

Can anyone help me figure this out?

This topic is closed to new replies. Start a new post to keep the conversation going.
Rob Hecker2
Rob Hecker2Correct answer
Legend
Mar 31, 2017 7:34 PM UTC

Ok, I went back to the roots so to speak. Started over again and localhost/phpinfo.php is working now. I did the form.php code again (first post) and when I click submit is still doesn't return any information. There's no error at all either, it's like the button doesn't have an action linked to when I click it.


Your form works, such as it is IF you change all the POST variables to lower case, including . . .

if (isset($_POST['submit'])) {

So here is the lesson:

Decide upon a naming convention for variable names, file names, etc. and stick with it. You've been stuck for days just because of a typo.

23 replies

Legend
Mar 27, 2017 10:32 PM UTC

You have plenty wrong with both your php code and your html code. Firstly 'Status' is not the same as 'status', 'Submit' is not the same as 'submit'. You need to make sure the name attribute assigned in your form tags is the same as what you use in the php code. I would get into a habit of using ALL lower case. If you are looking for some simple entry level example coding to get you familar with php then look at the code below. The information from the form fields is assigned and stored in php variables - $user, $pass, $status, $comments - you can then use those variables to output the information to the page or do what you require to do with them, like send them in an email etc. Below they get output to the page after the submit button is clicked.

<?php

if (isset($_POST['submit'])) {

$user =  $_POST['user'];

$pass = $_POST['pass'];

$status =   $_POST['status'];

$comments =   $_POST['comments'];

}

?>

<form method="post" action="">

User: <input type="text" name="user"><br>

Pass: <input type="password" name="pass"><br>

Status:

<input type="radio" name="status" value="Single">Single

<input type="radio" name="status" value="Married">Married

<input type="radio" name="status" value="Divorced">Divorced

<input type="radio" name="status" value="Widowed">Widowed<br>

Comments:<textarea name="comments"></textarea><br>

Submit:<input type="submit" name="submit" value="Submit">

</form>

<?php

if(isset($user)) {

echo "<p>User: $user</p>";

}

if(isset($pass)) {

echo "<p>Pass: $pass</p>";

}

if(isset($status)) {

echo "<p>Status: $status</p>";

}

if(isset($comments)) {

echo "<p>Comments: $comments</p>";

}

?>

Translate
cberlangaAuthor
Participating Frequently
Mar 27, 2017 10:52 PM UTC

I'm still getting the same error. I tried my original code with all lowercase and got the same error. I tried your code and I got the same error.

by the way, why do you have 2 different php codes? What's the function of the second one? I tried inserting it just like you wrote it but it didn't even get it as a code it just showed up on my HTML page.

Sorry, I know this may seem really simple to you but I'm barely learning and I just want to understand every single detail. I appreciate your response!

Translate
BenPleysier
Community Expert
Community Expert
Mar 27, 2017 11:00 PM UTC

Have you named your document with a PHP extension?

Translate
Wappler is the DMXzone-made Dreamweaver replacement and includes the best of their powerful extensions, as well as much more!