There is no problem with the code, why is it failing? "The ID inserted by the current user is 0"
phpcn_u46746
phpcn_u46746 2017-10-23 12:45:38
0
2
1431

<?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);

?>

phpcn_u46746
phpcn_u46746

reply all(2)
小崔

Check if there is already that record in the database, it cannot be repeated

路过
  1. Whether the sql statement corresponds to the database field

  2. Field issues in the sql statement

$ sql = "insert into user(`username`,`password`,`createtime`,`createip`) values ​​('" . $username . "','" . $password . "','" . $time . " ','" . $ip . "')";

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template