所以我对PHP很陌生,我试图创建一个登录表单,当用户输入数据库中的用户名和密码时,它会将它们重新定位回proj.php和将显示' welcome name '。我还没有添加该代码,因为到目前为止,当我使用正确的用户名和密码时,它会找到login.php,但不会将用户重新定位回主页。任何帮助 - 非常感谢!我也很欣赏我可能会遗漏一些代码......我还没有发现任何迄今为止有用的东西。
的login.php
//connection
$servername = "localhost";
$username = "root";
$password = "***";
$dbname = "login";
$conn = mysqli_connect($servername,$username,$password,$dbname);
if (!$conn) {die("connection failed; " . mysqli_connect_error());}
// Define $username and $password
$error=''; // Variable To Store Error Message
if (isset($_POST['submit'])) {
if (empty($_POST['dbusername']) || empty($_POST['dbpassword'])) {
$error = "Username or Password is invalid";
}
else
{
// Define $username and $password
$dbusername=$_POST['dbusername'];
$dbpassword=$_POST['dbpassword'];
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$result = mysqli_query("SELECT dbusername FROM login WHERE dbusername='$dbusername' and dbpassword='$dbpassword'", $conn);
$count=mysqli_num_rows($result, $conn);
$rows = mysqli_num_rows($query);
if ($count == 1) {
session_start();
$_SESSION['dbusername']= $_POST('dbusername');
header('Location: proj.php'); // Redirecting To Other Page
} else {
$error = "Username or Password is invalid";
}
}
}
?>
proj.php
<div id="main>"
<div id="login">
<form class="navbar-form navbar-right" action="login.php" method="post" name="myForm" onsubmit="return validateForm()">
<div class="form-group">
<input type="text" placeholder="Username" class="form-control" name="username" id="name">
</div>
<div class="form-group">
<input type="password" placeholder="Password" class="form-control" name="password" id="name">
</div>
<input type="submit" type=""name="submit" class="btn btn-success"></button>
</form>
<table border="0" cellpadding="10" cellspacing="1" width="500" align="center">
<script>
答案 0 :(得分:0)
这是脚本正在寻找的内容。
// Define $username and $password
$dbusername=$_POST['dbusername'];
$dbpassword=$_POST['dbpassword'];
输入错误命名:
用户名应为 dbusername
密码应为 dbpassword
<input type="text" placeholder="Username" class="form-control" name="dbpassword" id="name">
<input type="password" placeholder="Password" class="form-control" name="dbpassword" id="password">