<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style>.error {color: red;}</style>
</head>
<body>
<?php
//檢查(1)郵箱、密碼、昵稱是否為空;(2)郵箱格式是否正確。
global $emailErr,$passErr,$nicknameErr;
$emailErr = $passErr = $nicknameErr = "";
//$user_email = $user_pass = $user_nickname = "";
if (empty($_POST["user_email"])) {$emailErr = "不可為空";}
else
{
if (!preg_match("/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/",$_POST["user_email"])) {$emailErr = "email格式不正確";}
else {$emailErr="ok";}
}
if (empty($_POST["user_pass"])) {$passErr = "不可為空";} else {$passErr = "ok";}
if (empty($_POST["user_nickname"])) {$nicknameErr = "不可為空";} else {$nicknameErr = "ok";}
?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<p>注冊一個新用戶^_^</p>
郵箱:<input type="text" name="user_email"><span class="error">* <?php echo $emailErr;?></span><br><br>
密碼:<input type="text" name="user_pass"><span class="error">* <?php echo $passErr;?></span><br><br>
昵稱:<input type="text" name="user_nickname"><span class="error">* <?php echo $nicknameErr;?></span><br><br>
<input type="submit" name ='submit' value="注冊">
</form>
<?php
if ( isset($_POST["submit"]) && $emailErr="ok" && $passErr = "ok" && $nicknameErr = "ok" )
{
//連接數據庫
$con = mysql_connect(SAE_MYSQL_HOST_M.":".SAE_MYSQL_PORT,SAE_MYSQL_USER,SAE_MYSQL_PASS);
$con or die ('Could not connect: ' . mysql_error());
//選擇數據庫
mysql_select_db(SAE_MYSQL_DB,$con);
//獲取當前時間戮
$unix_timestamp=time();
//插入用戶注冊數據
$sql="INSERT INTO users
(user_email,user_pass,user_nickname,user_reg_ip,user_reg_date,user_last_log_ip,user_last_log_date,user_coins,user_rmb,user_email_status)
VALUES
('$_POST[user_email]','$_POST[user_pass]','$_POST[user_nickname]','$_SERVER[REMOTE_ADDR]','$unix_timestamp','$_SERVER[REMOTE_ADDR]','$unix_timestamp','0','0','0')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "注冊成功!";
//斷開數據庫連接
mysql_close($con);
}
else echo "not coming..";
?>
<br>
很高興遇見你,<?php echo $_POST["user_nickname"]; ?><br>
<a href="#">點此登陸...>>></a>
</body>
</html>
目測,在php中,判斷用的是==號,不是=號。