简体   繁体   中英

Cannot POST /file.php

I'm having a problem with php , the problem is I only get Cannot POST /file.php error after I click submit button. I'm using LAMPP and activate the webserver service , and I've place my project into /htdocs folder, but its still the same.

this is my code: html

<form id="flogin" method="post" action="phpe.php"> <!--form login-->
<input id="user" name="user" placeholder="username" type="text">
<input id="pass" name="pass" placeholder="password" type="password"><br>
<input id="bf" type="submit" value="login">
</form>

phpe.php:

<?php
$username="singduwe";
$password="websiteiki";

if($_POST["user"]==$username and $_POST["pass"]==$password){
    session_start();
    $_SESSION["admin"]="yes";
    header("location:admin.php");
}else{
    session_start();
    $_SESSION["admin"]="no";
    header("location:index.html");
}

?>

admin.php:

<?php
session_start();

?>

<html>
<head></head>
<body>
    hi</body>
</html>

update I'm using Brackets code editor

Gave your code a quick try and it works as expected. May be you are missing something in your setup? what is exact error message?

It looks to me like your webserver does not have PHP installed?

How did you install your LAMP stack? Since you said LAMP, i am assuming your server is linux.

Please check if php is installed on your server, if it is, is Apache configured to use PHP?

It is rather easy to install using yum or apt-get, based on your linux installation. Take a look at this https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu

To do a quick check if php is installed, create a test file with

<?PHP 
 phpinfo();
?>

If everything is well, you should see a bunch of PHP information...something like this

http://i.imgur.com/L0eospD.png

Your code is pretty straight forward and should not fail unless your setup is wrong. If you are windows user, try a locally hosted WAMP server; that will be helpful if you do not wish to fiddle with Linux.

Can you try to edit action="phpe.php" to action="yourdirectory/phpe.php"

It may work. If it'll still same, please give me more details.

Ensure your php file path is included in the portion of the code you are calling it. Sound like the project is not stored in the default htdocs folder. Cheers

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