我基本上有兩種形式在一個頁面。 第一個用於登錄,第二個用於插入數據。 二表單操作正常。我可以用它插入數據。 但我用於登錄用戶的相同形式,但它不起作用。 點擊提交按鈕後,什麼也沒有發生,只是頁面刷新。表單操作不工作在PHP?
請參閱我的代碼,並幫助我解決我的第一個表單的操作問題。
<div class="login_wrapper">
<div id="login" class="animate form login_form">
<section class="login_content">
<form action="login.php" method="post">
<h1>Login Form</h1>
<div>
<input type="text" class="form-control" placeholder="Username" required="" name="username" />
</div>
<div>
<input type="password" class="form-control" placeholder="Password" required="" name="password" />
</div>
<div>
<input type="submit" class="btn btn-default" name="insert" value="Sign In">
<a class="reset_pass" href="#forgetpass">Lost your password?</a>
</div>
<div class="clearfix"></div>
<div class="separator">
<p class="change_link">New to site?
<a href="#signup" class="to_register"> Create Account </a>
</p>
<div class="clearfix"></div>
<br />
<div>
<h1><i class="fa fa-paw"></i> DiGItal Society</h1>
<p>©2016 All Rights Reserved. DiGItal Society is a Web Portal for E-Society. Privacy and Terms</p>
</div>
</div>
</form>
</section>
</div>
<div id="register" class="animate form registration_form">
<section class="login_content">
<form action="insertUser.php" method="post">
<h1>Create Account</h1>
<div>
<input type="text" class="form-control" placeholder="Username" required="" name="username" />
</div>
<div>
<input type="email" class="form-control" placeholder="Email" required="" name="email" />
</div>
<div>
<input type="password" class="form-control" placeholder="Password" required="" name="password" />
</div>
<div>
<input type="hidden" name="roleid" value="">
<input type="submit" class="btn btn-default" name="insert" value="Log In">
</div>
<div class="clearfix"></div>
<div class="separator">
<p class="change_link">Already a member ?
<a href="#signin" class="to_register"> Log in </a>
</p>
<div class="clearfix"></div>
<br />
<div>
<h1><i class="fa fa-paw"></i> DiGItal Society</h1>
<p>©2016 All Rights Reserved. DiGItal Society is a Web Portal for E-Society. Privacy and Terms</p>
</div>
</div>
</form>
</section>
</div>
</div>
我還添加了我的操作頁面(不工作)。 login.php
爲第一種形式(不工作)
<?php
include 'db.php';
if (isset($_REQUEST['insert']))
{
echo $username = $_REQUEST['username'];
echo $password = $_REQUEST['password'];
$sql = mysqli_query($conn,"SELECT * FROM `accountants` where `acc_email` = '$username' AND `acc_pass` = '$password'");
$data = mysqli_fetch_array($conn,$sql);
$_SESSION['role']=$data['roleId'];
$_SESSION['username']=$data['acc_name'];
$data = mysqli_num_rows($data);
if ($data>0)
{
header('Location: home.php');
}
else
{
header('Location: index.php');
echo 'incorrect login';
}
}
?>
爲第二形式
和insertUser.php
。(工作)
<?php
include 'db.php';
if (isset($_REQUEST['insert']))
{
$acc_name = $_REQUEST['username'];
$acc_email = $_REQUEST['email'];
$acc_pass = $_REQUEST['password'];
$role_id = $_REQUEST['roleid'];
$sql = mysqli_query($conn,"INSERT INTO `accountants`(`acc_name`, `acc_email`, `acc_pass`, `roleId`) VALUES ('".$acc_name."','".$acc_email."','".$acc_pass."','2')");
if ($sql>0)
{
header('Location: home.php');
echo 'data added successfully';
}
$row = mysqli_query('SELECT * FROM `accountants`');
$data = mysqli_fetch_array($row);
$data = mysqli_num_rows($conn,$data);
$_SESSION['role'] = $data['roleId'];
}
?>
在輸入提交中爲第一個表單嘗試使用不同的'name'。並使用它在login.php –
@KinshukLahiri好吧,我嘗試它但不工作。還在同一頁 –
這個'print_r($ _ REQUEST)的輸出是什麼?的print_r($ _ POST [ 「插入」])';死;'爲login.php文件。 –