<?php
session_start();
//註冊處理介面regcheck.php
if(isset($_POST["hidden"]) && $_POST["hidden"] == "hidden")
{
$user = trim($_POST["username"]);//trim()函數移除字串兩側的空白字元
$psw = md5(trim($_POST["userpwd"]));
$psw_confirm = md5(trim($_POST["confirm"])) ;
$code = $_POST["code"];
if($user == "" || $psw == "" || $psw_confirm == "")
{
echo "<script>alert('請確認訊息完整性!'); history.go(-1);</script>";
# }
else if($code != $_SESSION[' ver_code']){
echo "<script>alert('驗證碼不正確,請重新輸入!') ; history.go(-1);</script>";
}
else
{
# if($psw == $ psw_confirm)
{
$conn = mysqli_connect("localhost","root","root"); //連結資料庫,帳號密碼為自己資料庫的帳號密碼
## if(mysqli_errno($conn)){
echo mysqli_error($conn);
exit;
}
mysqli_select_db($conn, "userdb"); //選擇資料庫
mysqli_set_charset($conn,'utf8'); //設定字元集
$sql = "select username from user where username = '$ user'"; //SQL語句
$result = mysqli_query($conn,$sql); //執行SQL語句
$num = mysqli_num_rows($result); //統計執行結果影響的行數
if($num) //如果已經存在該使用者
{
echo "<script>alert( '使用者名稱已存在'); history.go(-1);</script>";
}
else //不存在目前註冊使用者名稱
# {
$ip=ip2long($_SERVER['REMOTE_ADDR']); // 把ip位址轉換成整數
$time=time();
# $sql_insert = "insert into `user` (`username`,`userpwd`,`createtime`,`createip`) values('" . $user . "','" . $psw ."','".$ time."','".$ip."')";
$res_insert = mysqli_query($conn,$sql_insert);
# if($res_insert)
# {
echo "<script>alert('註冊成功! ');window.location.href='login.php';</script>";
}
else
# {
echo "<script>alert('系統繁忙,請稍候!'); history.go(-1);</script>";
}
#######}
}
else
{
echo "<script>alert('密碼不一致!'); history.go( -1);</script>";
}
# }
}
else
{
## else
## else
分別列印$code和$_SESSION[' ver_code'],看看有沒有資料