<?php
if (trim($_POST['password']) != trim($_POST['repassword'])) {
exit('twice The password is inconsistent, please return to the previous page');
}
$username = trim($_POST['username']);
$password = md5(trim ($_POST['password']));
$time = time();
$ip = $_SERVER['REMOTE_ADDR'];
$conn = mysqli_connect('localhost', 'root', 'root');
//If there is an error, there is an error number
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 'success';
} else {
echo 'failed';
}
echo 'The ID inserted by the current user is' . mysqli_insert_id($conn);
mysqli_close( $conn);
?>
小崔2018-03-23 10:50:51
Check if there is already that record in the database, it cannot be repeated
路过2017-10-23 13:10:43
Whether the sql statement corresponds to the database field
Field issues in the sql statement
$ sql = "insert into user(`username`,`password`,`createtime`,`createip`) values ('" . $username . "','" . $password . "','" . $time . " ','" . $ip . "')";