在我的網站上我有一個註冊表。用戶只需輸入電子郵件,密碼並重新輸入密碼即可。PHP不提交用戶的詳細信息到數據庫?
但是,即使填寫了所有字段,我仍然收到一個錯誤,表示我沒有填寫表格。我不明白我做錯了什麼(PHP相對較新)
請注意我沒有嘗試清理用戶輸入,因此我知道我的代碼將容易受到SQL注入!
<?php
include("database.php");
include("requirements.php");
if(isset($_POST['register'])) {
$email = $_POST['email'];
$password = $_POST['password'];
$confpassword = $_POST['confpassword'];
}
if(isset($password) && isset($email) && isset($confpassword)){
if($password != '' && $email != '' && $confpassword != ''){
if($password == $confpassword){
if(strlen($password) <= 20 && strlen($password) >= 6){
if(strlen($email) > 6){
$hash = password_hash($password, PASSWORD_DEFAULT);
$insert_user = mysqli_query($con, "INSERT INTO users (email, password, salt) VALUES ('".$email."', '".$password."', '".$salt."')");
if($insert_user)
{
echo "Thank you for registering, you can now login to your account and create a listing.";
}
else
{
echo "Sorry there was an error - please try again later. If the issue continues please contact support.";
}
}
else
{
echo "You need to insert an email.";
}
}
else
{
echo "The entered email address needs to be above 6 characters.";
}
}
else
{
echo "The password must be between 6 and 20 characters long.";
}
}
else
{
echo "The two passwords you have entered do not match.";
}
}
else
{
echo "You have not inserted all of the required fields that were needed.";
}
它只是跳到最後說「你沒有插入所有需要的字段。」甚至不嘗試查詢數據庫。
database.php中只是有數據庫信息(表,密碼等)
感謝您的連接!
原來,這是HTML - 在我的表單中,我的「Value =」註冊「」在我的按鈕上,而不是「佔位符=」註冊「」......菜鳥錯誤。多謝你們! – PublicDisplayName
不客氣;) – Lemurantin