我正在尝试设置用户注册并使用PHP和MySQL登录。我似乎已经到达了应该工作的地步,但是在实际单击"寄存器"按钮后,我正在努力获得空白页以外的任何东西。我知道数据库正在稳定连接,因为更改我的" db.php"文件中的凭据会导致错误。我试图使PHP显示错误,但无济于事,仍然是空白页!
以下代码中是否有任何可能引起问题的东西?有错误处理代码,无论注册的成功如何,都应显示形式,但仅显示空白。
<html>
<head>
<title>Registration</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<?php
require('db.php');
if (isset($_REQUEST['username'])) // If form submitted, insert values into the database.
{
$username = stripslashes($_REQUEST['username']); // removes backslashes
$username = mysqli_real_escape_string($con,$username); //escapes special characters in a string
$email = stripslashes($_REQUEST['email']);
$email = mysqli_real_escape_string($con,$email);
$password = stripslashes($_REQUEST['password']);
$password = mysqli_real_escape_string($con,$password);
$query = "INSERT INTO users (username, password, email) VALUES ('$username', '".md5($password)."', '$email')";
$result = mysqli_query($con,$query);
echo $result;
if($result) {
echo "<div class='form'><h3>You are registered successfully.</h3><br>Click here to <a href='login.php'>Login</a></div>";
}
} else {
?>
<div class="form">
<h1>Registration</h1>
<form name="registration" action="" method="post">
<input type="text" name="username" placeholder="Username" required />
<input type="email" name="email" placeholder="Email" required />
<input type="password" name="password" placeholder="Password" required />
<input type="submit" name="submit" value="Register" />
</form>
</div>
<?php } ?>
</body>
多亏了Riggsfolly给我的一些错误报告,我设法看到了电子邮件地址的列名不正确。修复此问题。
方便的提示。谢谢。
这是错误的。
if (isset($_REQUEST['username']))
您正在提交表单,并且在REQUEST
变量中应该有表格的名称。这样做
虽然应该是
if (isset($_REQUEST['registration']))
或
if (isset($_POST['submit']))
{
$username = stripslashes($_POST['username']);
$email = stripslashes($_POST['email']);
$password = stripslashes($_POST['password']);