所以我只是为PHP做了一个非常基本的注册,而且......每次我尝试运行它时,它只返回一个空白页面,没有错误或回声,只是一个简单的空白页面。我希望你们能解释一下为什么我的代码中没有明显的错误。
这是我的reg.php文件:
<html>
<head>
<title>Registered!</title>
</head>
<body>
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'username');
define('DB_PASSWORD', 'password');
define('DB_DATABASE', 'database');
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
if(isset($_POST['submit']))
{
$name = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
$username = mysqli_real_escape_string($db, $name);
$email = mysqli_real_escape_string($db, $email);
$password = mysqli_real_escape_string($db, $password);
$query = mysqli_query($db, "INSERT INTO users (username, password,
email)VALUES ('$name', '$password', '$email')");
if($query)
{
echo "You are now registered!";
}
else
{
echo "failed";
}
}
?>
</body>
</html>
这是我的html表单部分
<div id="id01" class="modal">
<form class="modal-content animate" action="reg.php" method="post">
<div class="container">
<label><b>Username</b></label>
<input type="text" placeholder="Enter Username" id="username"
name="username" required>
<label><b>Password</b></label>
<input type="password" placeholder="Enter Password" id="password"
name="password" required>
<label><b>Email</b></label>
<input type="text" placeholder="Enter Email" id="email" name="email"
required>
<button class="btn waves-effect waves-light teal lighten-1" type="submit"
name="submit" id="submit" value="submit">Submit<i class="material-icons
right">send</i></button>
</div>
</form>
</div>
是的,我知道,这个表单对SQL注入是开放的,只要我能够实际获得基本表单,我就会处理它!
对不起,我知道这可能最终会成为一些愚蠢的修复,但我无法理解我的生活......
谢谢大家!
答案 0 :(得分:0)
您的代码中存在SQL错误,请尝试更改:
$ query = mysqli_query($ db,“INSERT INTO users(用户名,密码, 电子邮件)VALUES('$ name','$ password','$ email')“);
到
$ query = mysqli_query($ db,“INSERT INTO users(用户名,密码, 电子邮件)VALUES('$ name','$ password','$ email')“);