<?php
if (trim($_POST['password']) != trim($_POST['repassword'])) {
exit('兩次密碼不一致,請回上一頁');
}
$username = trim($_POST['username']);
$password = md5(trim ($_POST['password']));
$time = time();
$ip = $_SERVER['REMOTE_ADDR'];
#$conn = mysqli_connect('localhost', 'root', 'root');
//如果有錯誤,有錯誤編號
if (mysqli_errno($conn)) {
echo mysqli_error ($conn);
exit;
}
mysqli_select_db($conn, 'text');
mysqli_set_charset($conn, 'utf8');
$sql = "insert into user(username,password,createtime,createip) values('" . $username . "','" . $password . "','" . $time . "', '" . $ip . "')";
$result = mysqli_query($conn, $sql);
if ($result) {
echo '成功';
} else {
echo '失敗';
}
echo '目前使用者插入的ID為' . mysqli_insert_id($conn);
#mysqli_close( $conn);
?>
路过2017-10-23 13:10:43
sql語句是否與資料庫欄位對應
sql語句裡面的欄位問題
$ sql = "insert into user(`username`,`password`,`createtime`,`createip`) values ('" . $username . "','" . $password . "','" . $time . " ','" . $ip . "')";