【发布时间】:2017-09-01 00:13:32
【问题描述】:
我基本上在一页中有 2 个表格。 第一个用于登录,第二个用于插入数据。 第二种形式的行动工作正常。我可以用它插入数据。 但是我用于登录用户的相同表单但它不起作用。 单击提交按钮时,页面刷新不会发生任何事情。
请查看我的代码并帮助我解决第一个表单的操作问题。
<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["insert"])的输出是什么; die;` 用于 login.php 文件。 -
@KinshukLahiri 我收到了
Array ( [user] => a [pass] => a [login] => Sign In )的请求。但是如果我使用 request 并且死了,那么问题是什么 -
@amitsutar 这是一个直播网站还是即将上线的网站?