0
我製作了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注入攻擊(HTTP:你需要[防守](http://stackoverflow.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