<?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);
?>
看看数据库里面是不是已经有了那条记录了,不能重复的
sql语句是否与数据库字段对应
sql语句里面的字段问题
$sql = "insert into user(`username`,`password`,`createtime`,`createip`) values ('" . $username . "','" . $password . "','" . $time . "','" . $ip . "')";