它看起来像我可以在我的表单页上注册一个新用户,但没有对phpmyadmin仪表板执行操作
问题描述:
我制作了3页:表单,数据库连接和注册页面。我没有收到任何错误,但是当我在表单页面上注册新用户时,它并没有在phpmyadmin仪表板上显示。它看起来像我可以在我的表单页上注册一个新用户,但没有对phpmyadmin仪表板执行操作
请帮我
我该怎么办?
我的形式是在这里:
<!DOCTYPE html> <html> <head>
<title></title> <meta charset="utf-8"> </head> <body> <div
style="background-color: #222; color: #fff; height: 50px; width:
100%;"></div> <style type="text/css"> body{ background-color:
#e1e1e1; } form{ margin-top: 20px; background-color: #fff;
} form input{ padding: 4px; }
button{ width: 100px; height: 35px; background-color: #222;
color: #fff; margin-top: 10px; border: 2px dotted; }
</style> <form action="register.php" method="POST"> Forname:<br> <input type="text" name="first" id="first"
size="50"><br> Aftername:<br> <input type="text" name="last"
size="50"><br> E-post:<br> <input type="text" name="email"
size="50"><br> Username:<br> <input type="text" name="username"
size="50"><br> Password:<br> <input type="password" name="password"
size="50"><br> <button type="submit" name="submit"
id="btn-submit">Sign Up</button>
</form> </body> </html>
我的数据库连接:
<?php $conn =
mysqli_connect("127.0.0.1","root", "","test1"); if (!$conn) {
die("You can't connect to the database");
} else echo "Your registration is succesed";
?>
我的注册页面:
<?php require 'db.php'; ?> <?php
if(isset($_POST['submit'])){ session_start(); $hostname =
"127.0.0.1"; $username = "root"; $password = ""; $database = "login";
$first = $_POST['first']; $last = $_POST['last']; $email =
$_POST['email']; $username = $_POST['username']; $password =
$_POST['password'];
$sql = $conn->query("INSERT INTO
users(first,last,email,username,password)values('{$first}','{$last}','{$email}','{$password}')");
header('Location: login.php'); }
?>
答
对于插入SQL,建议您显示错误无论是否插入,例如w3school:PHP insert Data into MySQL
并可根据您的代码,你错过了$ username列值,替换这个和问题解决
$sql = "INSERT INTO users(first,last,email,username,password)
values('{$first}', '{$last}', '{$email}', '{$username}', '{$password}')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
+0
哇,它的工作,非常感谢你的时间,并帮助“ –
** **危险:你是**易受[SQL注入攻击(HTTP:你需要[防守](http://*.com/questions/60174/best-way-to-prevent-sql-injection-in-php)。 – Quentin
**危险**:“不哈希”是[不适合的哈希算法](http://php.net/manual/en/faq.passwords.php);你需要[更好地照顾](https://www.owasp.org/index.php/Password_Storage_Cheat_Sheet)你的用户密码。 – Quentin