Jump to content

Error 405 Not Allowed nginx


Go to solution Solved by mac_gyver,

Recommended Posts

Hello. I was building my first site and I've already done login and register forms. Then I've finished register form to send new records to the database and it was working. Every time I've filled register form, it was adding new records to the "users" table in my database. Then I was trying to finish login and make sessions, but the problem appeared. I don't know if it's caused by database new column I've added to the users table, or because of the code in my scripts, but now every time I'm trying to send filled registration form it displays this strange error.

 

I was trying to step back by sending my working backup files back to the server, didn't helped. I've also removed these new columns from users table, didn't helped. I've deleted all tables and imported from working backup. Still nothing, same error. What is happening? I got 7 php scripts, I don't know which one should I share

Edited by Shredon
Link to comment
https://forums.phpfreaks.com/topic/315085-error-405-not-allowed-nginx/
Share on other sites

register.php looks like this:

 

<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Rejestracja</title>
        <link rel="icon" href="./pic/icon.png">
    </head>
    <body style="background-color:#000000;">
        <main>
            <link rel="stylesheet" type="text/css" href="style.php"/>
        
            <div class="logRegSiteImage">
            <br>
            <div class="logRegSiteText">asdfasdf</div>
            <div class="logRegSite2Text">asdfasdf</div>
            <br><br><br>
            <div class="logRegSite3Text">asdfasdf</div>
            <br><br>
            <div id="blackBG">
            <a href="./login.php" class="myButtonLOG">Zaloguj się</a>
            <a href="./register.php" class="myButtonREG">Zarejestruj się</a>
            </div>
            <br><br><br>
            <table class="horizontalCenter">
                <thead>
                    <tr>
                    <th colspan="3" class="logRegSite3Text">Rejestrowanie</th>
                    </tr>
                </thead>
                <tbody>
                    <form action="registerFinal.php" method="post"><!-- ten fragment inputow jest wysylany submitem do pliku registerFinal.php -->
                    <tr class="logRegSiteTextBox">
                        <td>login: </td>
                        <td><input type="text" placeholder="tak" title="nie" required></td>
                    </tr>
                    <tr class="logRegSiteTextBox">
                        <td>e-mail: </td>
                        <td><input type="text" placeholder="tak" title="nie" required></td>
                    </tr>
                    <tr class="logRegSiteTextBox">
                        <td>hasło: </td>
                        <td><input type="password" placeholder="tak" title="nie" required></td>
                    </tr>
                    <tr class="logRegSiteTextBox">
                        <td>powtórz hasło: </td>
                        <td><input type="password" placeholder="tak" title="nie" required></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td><input type="submit" value="Zarejestruj się" class="myButtonREG"></td>
                    </tr>
                    </form>

                </tbody>
            </table>
            </div>


        </main>
    </body>
</html>



The registerFinal.php looks like that:
 

<?php
require("connect.php");

$REGlogin = $_POST['loginREGfield'];
$REGemail = $_POST['emailREGfield'];
$REGpassword = $_POST['passwordREGfield'];

$sql = "INSERT INTO users(users_id, users_username, users_password, users_email, users_galaxy, users_starsystem, users_planet, users_planetid) VALUES ('','$REGlogin','$REGpassword','$REGemail','','','','')";
$result = $conn->query($sql);
?>


 

And the connect.php looks like this:
 

<?php
    $conn = mysqli_connect(
    'localhost',
    'xxx',
    'xxx',
    'xxx'
    );
?>


 

I really don't know what to do... Backups doesn't helps... even database backups

$_POST from your inputs works by input name which I see none of.

 

So your form should be like:

 

 <form action="registerFinal.php" method="post"><!-- ten fragment inputow jest wysylany submitem do pliku registerFinal.php -->
                    <tr class="logRegSiteTextBox">
                        <td>login: </td>
                        <td><input type="text" name="loginREGfield" placeholder="tak" title="nie" required></td>
                    </tr>
                    <tr class="logRegSiteTextBox">
                        <td>e-mail: </td>
                        <td><input type="text" name="emailREGfield" placeholder="tak" title="nie" required></td>
                    </tr>
                    <tr class="logRegSiteTextBox">
                        <td>hasło: </td>
                        <td><input type="password" name="passwordREGfield" placeholder="tak" title="nie" required></td>
                    </tr>
                    <tr class="logRegSiteTextBox">
                        <td>powtórz hasło: </td>
                        <td><input type="password" placeholder="tak" title="nie" required></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td><input type="submit" value="Zarejestruj się" class="myButtonREG"></td>
                    </tr>
                    </form>

                

you also need a name in your powtórz hasło input if you are using it in $_POST.

Edited by dodgeitorelse3
gave example
9 minutes ago, dodgeitorelse3 said:

$_POST from your inputs works by input name which I see none of.

Im sorry, I just forgot to add it because it's earlier version of that script, but this:

<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta http-equiv="X-UA-Compatible" content="ie=edge">
		<title>Rejestracja</title>
		<link rel="icon" href="./pic/icon.png">
	</head>
	<body style="background-color:#000000;">
		<main>
			<link rel="stylesheet" type="text/css" href="style.php"/>
		
			<div class="logRegSiteImage">
			<br>
			<div class="logRegSiteText">asdfasdf</div>
			<div class="logRegSite2Text">asdfasdf</div>
			<br><br><br>
			<div class="logRegSite3Text">asdfasdf</div>
			<br><br>
			<div id="blackBG">
			<a href="./login.php" class="myButtonLOG">Zaloguj się</a>
			<a href="./register.php" class="myButtonREG">Zarejestruj się</a>
			</div>
			<br><br><br>
			<table class="horizontalCenter">
				<thead>
					<tr>
					<th colspan="3" class="logRegSite3Text">Rejestrowanie</th>
					</tr>
				</thead>
				<tbody>
					<form action="registerFinal.php" method="post"><!-- ten fragment inputow jest wysylany submitem do pliku registerFinal.php -->
					<tr class="logRegSiteTextBox">
						<td>login: </td>
						<td><input type="text" placeholder="tak" title="nie" name="loginREGfield" required></td>
					</tr>
					<tr class="logRegSiteTextBox">
						<td>e-mail: </td>
						<td><input type="text" placeholder="tak" title="nie" name="emailREGfield" required></td>
					</tr>
					<tr class="logRegSiteTextBox">
						<td>hasło: </td>
						<td><input type="password" placeholder="tak" title="nie" name="passwordREGfield" required></td>
					</tr>
					<tr class="logRegSiteTextBox">
						<td>powtórz hasło: </td>
						<td><input type="password" placeholder="tak" title="nie" required></td>
					</tr>
					<tr>
						<td></td>
						<td><input type="submit" value="Zarejestruj się" class="myButtonREG"></td>
					</tr>
					</form>

				</tbody>
			</table>
			</div>


		</main>
	</body>
</html>

still doesn't working. Error is just same

Edited by Shredon

Are register.php, registerFinal.php and connect.php all located in same directory? and are the names spelled right for those 3 files?

 

Also in your registerFinal.php file change

require("connect.php");

to

require "connect.php";

HTTP 405 is an HTTP response status code. There are five classes of HTTP response status codes. They all inform a user whether a specific HTTP request has been successfully completed. The five core status codes include:

 

1xx status codes: Informational requests

2xx status codes: Successful requests

3xx status codes: Redirects

4xx status codes: Client errors

5xx status codes: Server errors  

 

The 405 Method Not Allowed error message is a client error, which indicates that something on the client-side of things is the issue.

 

An HTTP 405 Error indicates that a web browser has requested access to one of your pages, and your web server has recognized the request. However, the server has rejected the specific HTTP method it's using. As a result, your web browser can't access the requested web page.

Edited by dodgeitorelse3
added suggestion

Yes, and yes. I just have one folder for images, but every scrypt is outside of it in same location

I've changed require("connect.php"); to require "connect.php"; but still 405 Not Allowed nginx shows

Edited by Shredon

I think this error started to appear when I've added timestamp column for the date of registration to the "users" table in database. I did it manually through phpMyAdmin... but it's strange, because then I've deleted this column to go back to the previous table structure... But error didn't disappeared

while this isn't the cause of the problem, you need to validate the resulting web page(s) at validator.w3.org  you cannot spread the markup for a form throughout a html table. you can put a compete html table inside a form and you can put a complete form inside a single table data cell <td>...</td>, but you cannot intermix the markup for a table and a form.

also, the form and form processing code should be on the same page. this will simplify all the code. the code for a page should be laid out in this general order -

  1. initialization
  2. post method form processing
  3. get method business logic - get/produce data needed to display the page
  4. html document

post method from processing code should -

  1. detect if a post method form was submitted.
  2. keep the form data as an array variable, then operate on elements in this array variable throughout the rest of the code.
  3. trim all the inputs at once. when you do item #2 on this list, you can trim all the data using one single line of code.
  4. validate all the inputs, storing validation errors in an array using the field name as the array index.
  5. after the end of all the validation logic, if the array holding the errors is empty, use the submitted form data.
  6. an insert/update query can result in duplicate data for things that must be unique, such as a username or email column. your code should handle query errors in these cases. the simplest way of doing this is to use exceptions for database statement errors and have exception try/catch logic only is these cases. the catch logic would test the error number and if it is for something that the visitor can correct, setup a message telling the visitor exactly what was wrong with the data that they submitted, so that they can potentially submit new value(s) that will succeed. for all other error numbers, just re-throw the exception and let php handle it.
  7. after the end of the form processing logic, if there are no errors, redirect to the exact same URL of the current page to cause a get request for the page. this will prevent the browser from trying to resubmit the form data should the visitor reload the page or navigate away from and back to that URL.
  8. if you want to display a one-time success message, store it in a session variable, then test, display, and clear that session variable at the appropriate location in the html document.
  9. if there are errors at item #5 on this list, the code would continue on to display the html document, display any errors, redisplay the form, populating the field values with any existing data.
  10. any dynamic value you output on a web page should have htmlentities applied to it to help prevent cross site scripting.

the http 405 error means you are using a method that isn't supported or configured correctly. this isn't being cause by anything you are doing with the database server. what is the actual URL of the form page and what is the url in the browser's address bar after you submit the form?

as a test, to see if just a basic form will work, make a new .php page with the following and test it -

<?php

echo '<pre>'; print_r($_POST); echo '</pre>';

?>

<form method='post'>
<input type='text' name='somefield'>
<input type='submit'>
</form>

after you submit the form, the print_r output should show an array with the field name as an index and whatever value you type into the field.

also, if you are just starting out, learn and use the much simpler and better designed PDO database extension. don't put data values directly into an sql query statement. you should be using a prepared query when supplying external, unknown, dynamic values to the query when it gets executed.

URL of my site is http://testnowejgierki.cba.pl. Then after clicking "Zarejestruj się" (register), it goes to the register.php, because this is index of course. Then after clicking submit ("Zarejestruj"), it shows that error with URL http://testnowejgierki.cba.pl/registerFinal.php

see if the web server error log contains any additional information.

you should be using a localhost development system when learning, developing, and debugging code/query(ies). doing this on a live/public server wastes a bunch of time constantly uploading files to see the result of each change and since your code is not secure, can allow someone to abuse your web hosting. only put complete, secure code onto a live/public web site.

 

Im sorry, but I don't understand totally 😓. I was using many tutorials to write that "site" and it was going easy until this moment. My registration was working, but now it doesn't. I don't even know how to test it because its always showing me that error and Im soo newbie 😭. I don't know where to put this exactly

<?php

echo '<pre>'; print_r($_POST); echo '</pre>';

?>

<form method='post'>
<input type='text' name='somefield'>
<input type='submit'>
</form>

 

 

Now I got this here and I've modified form by deleting action="registerFinal.php" from it, but still shows that error:

				<tbody>
					<form method="post"><!-- ten fragment inputow jest wysylany submitem do pliku registerFinal.php -->
					<tr class="logRegSiteTextBox">
						<td>login: </td>
						<td><input type="text" placeholder="tak" title="nie" name="loginREGfield" required></td>
					</tr>
					<tr class="logRegSiteTextBox">
						<td>e-mail: </td>
						<td><input type="text" placeholder="tak" title="nie" name="emailREGfield" required></td>
					</tr>
					<tr class="logRegSiteTextBox">
						<td>hasło: </td>
						<td><input type="password" placeholder="tak" title="nie" name="passwordREGfield" required></td>
					</tr>
					<tr class="logRegSiteTextBox">
						<td>powtórz hasło: </td>
						<td><input type="password" placeholder="tak" title="nie" required></td>
					</tr>
					<tr>
						<td></td>
						<td><input type="submit" value="Zarejestruj się" class="myButtonREG"></td>
					</tr>
					</form>
					
					<?php

					echo '<pre>'; print_r($_POST); echo '</pre>';

					?>

					
				</tbody>

 

 

I cannot mix form with html table... then Im not mixing it now:

<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta http-equiv="X-UA-Compatible" content="ie=edge">
		<title>Rejestracja</title>
		<link rel="icon" href="./pic/icon.png">
	</head>
	<body style="background-color:#000000;">
		<main>
			<link rel="stylesheet" type="text/css" href="style.php"/>
		
			<div class="logRegSiteImage">
			<br>
			<div class="logRegSiteText">Fraktomeda</div>
			<div class="logRegSite2Text">Rozległy Wszechświat czeka!</div>
			<br><br><br>
			<div class="logRegSite3Text">Strategiczna gra przeglądarkowa, w której przejmujesz władzę nad planetą, aby wkrótce kolonizować kolejne światy, zawierać sojusze i niszczyć wrogów. To tutaj doświadczysz ogromu Wszechświata, jego wszelkich wspaniałości oraz zjawisk które badane są przez naukowców od wieków. Przejmij dowodzenie już teraz i pokaż, jak buduje się potęgę międzygalaktyczną!</div>
			<br><br>
			<div id="blackBG">
			<a href="./login.php" class="myButtonLOG">Zaloguj się</a>
			<a href="./register.php" class="myButtonREG">Zarejestruj się</a>
			</div>
			<br><br><br>
			<table class="horizontalCenter">
				<thead>
					<tr>
					<th colspan="3" class="logRegSite3Text">Rejestrowanie</th>
					</tr>
				</thead>
				<tbody>
					<!--<form method="post"><!-- ten fragment inputow jest wysylany submitem do pliku registerFinal.php
					<tr class="logRegSiteTextBox">
						<td>login: </td>
						<td><input type="text" placeholder="tak" title="nie" name="loginREGfield" required></td>
					</tr>
					<tr class="logRegSiteTextBox">
						<td>e-mail: </td>
						<td><input type="text" placeholder="tak" title="nie" name="emailREGfield" required></td>
					</tr>
					<tr class="logRegSiteTextBox">
						<td>hasło: </td>
						<td><input type="password" placeholder="tak" title="nie" name="passwordREGfield" required></td>
					</tr>
					<tr class="logRegSiteTextBox">
						<td>powtórz hasło: </td>
						<td><input type="password" placeholder="tak" title="nie" required></td>
					</tr>
					<tr>
						<td></td>
						<td><input type="submit" value="Zarejestruj się" class="myButtonREG"></td>
					</tr>
					</form>-->
					

					
				</tbody>
			</table>
			</div>
			<form method="post">
			<input type="text" placeholder="tak" title="nie" name="loginREGfield" required>
			</form>
			<?php
			echo '<pre>'; print_r($_POST); echo '</pre>';

			?>

		</main>
	</body>
</html>

Not working, same problem

Edited by Shredon
  • Solution

i suspect the error is due to exceeding some limit at your free/cheap web hosting -

Quote

 

PRO and VIP packages are intended for more demanding customers for whom the limitations of the free package prevent the development of projects.

 

you might ask their support group.

21 minutes ago, Shredon said:

I don't know where to put this exactly

already stated -

2 hours ago, mac_gyver said:

make a new .php page with the following

 

Yup, i just noticed my FREE hosting expired 24.07.2022 so today. I've paid that like 2$ and it's working again. Thank you :). And also thank you for explaining 1xx 2xx 3xx 4xx 5xx errors. By the way if it's not good to mix <form> with <table>, how to construct the login/register form witout the table?

2 hours ago, Shredon said:

By the way if it's not good to mix <form> with <table>, how to construct the login/register form witout the table?

You can use a table in a form, but you can't embed the form within the table the way you did.  A <tbody> element can only contain <tr> elements, not <form> elements.

Move your form outside of the table entirely.

<form method="post">
  <table>
    ...
  </table>
</form>

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.