我在PHP中有一個「註冊」頁面,我希望腳本在單擊HTML按鈕時運行。PHP/MySQL - 更新數據庫/在按鈕上運行PHP腳本點擊
PHP主要檢查是否所有字段都已填充,檢查密碼和電子郵件確認是否相同並保存到數據庫。
這是代碼:
<?php
$Name = isset($_POST['Name']);
$Surname = isset($_POST['Surname']);
$Username = isset($_POST['Username']);
$Email = isset($_POST['Email']);
$C_Email = isset($_POST['C_Email']);
$Password = isset($_POST['password']);
$C_Password = isset($_POST['c_password']);
$SecQ = isset($_POST['SecQ']);
$SecA = isset($_POST['SecA']);
$con = mysql_connect('localhost', 'admin', 'storefile1234');
mysql_select_db ("storefile");
$check_username = mysql_query("SELECT FROM users WHERE username = '$Username'");
$check_email = mysql_query("SELECT FROM users WHERE Email = '$Email'");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
if ($Name == null || $Surname== null || $Username == null || $Password == null || $C_Password == null || $Email == null || $C_Email == null || $SecQ == null || $SecA == null) {
echo "Missing details. Please enter all fields.";
} else {
if(mysql_num_rows($check_username) != 0 && mysql_num_rows($check_email) != 0)
{
echo "Username/Email already exists";
}
if ($Email == $C_Email && $Password == $C_Password) {
$query = "INSERT INTO users (Username, Name,Surname, Password, Email, SecQ, SecA) VALUES ('NULL', ".$Username."', ".$Name."', ".$Surname."', ".$Password."', ".$SecQ."', ".$SecA."', ".$Email.')"';
mysql_query($query) or die ('Error registering.');
echo "Greetings, ".$Name.", you have been registered. ";
} else {
echo "Error registering your account. Please try again.";
}
}
?>
而且,它建議?
每當我跑這頁Missing details. Please enter all fields.
顯示,沒有輸入任何細節。
你是如何做到這一點的?
offtopic:不要使用'mysql_ *'函數。 Beter用**'PDO' **看準備好的陳述。 – Stranger