提交POST方法而不是调用PHP代码

时间:2017-06-24 16:16:40

标签: php

我正在努力让我的提交POST方法正常工作。如果我输入我的用户名和密码,按钮不会让我看到我应该看到的回声。它根本没有显示任何东西。在提交帖子之后我也尝试发出回音,没有任何事情发生,在此之前我无法看到出了什么问题。我用了一些网站尝试自己拿出来。我希望你们能帮助我!

PHP:

 <?php 
// validate the form for loggin the user 
//Function Login(){


//server info
$server = 'Localhost';
$user = 'root';
$pass = '';
$db = 'CMS';

//connect to database
$mysqli = new mysqli($server, $user, $pass, $db);

//show errors 
mysqli_report(MYSQLI_REPORT_ERROR);
//}

session_start();
//login();

if(isset($_POST['submit']))
{
$username = ($_POST['uname']);
$password = ($_POST['psw']);
$query = "SELECT username, password FROM user WHERE username='$username' 
AND password='$password'";

$result = mysqli_query($mysqli,$query)or die(mysqli_error());
$num_row = mysqli_num_rows($result);
$row=mysqli_fetch_array($result);

if( $num_row ==1 )
   {
        $_SESSION['userid']=$row['userid'];
        echo 'hi there';
        exit;
   }

else
   {
        echo 'oops can not do that';
   }

}
?>

html:

<form action="" method="post">
<input type="Text" placeholder ="Enter Username" name="uname" required> <br />
<input type ="Password" placeholder ="Enter Password" name="psw" required> <br />
<button type="submit">Login</button>
</form>

所有这些代码都在一个文档中

1 个答案:

答案 0 :(得分:1)

您的代码中有空操作(action ="") 在行动中你应该为你的php代码文件确定网址

<form action="/your_path/your_php_file.php" method="post">
    <input type="Text" placeholder ="Enter Username" name="uname" required> <br />
    <input type ="Password" placeholder ="Enter Password" name="psw" required> <br />
    <button type="submit">Login</button>
</form>

或者如果在一个.php文件中

删除action = ""

<form  method="post">
    <input type="Text" placeholder ="Enter Username" name="uname" required> <br />
    <input type ="Password" placeholder ="Enter Password" name="psw" required> <br />
    <button type="submit">Login</button>
</form>