php用户注册常用检测、写入
// 判断数据库是否已经存在 $check_sql = "select * from user where idNumber='$idNumber'"; $check_query = $conn->query($check_sql); if ($check_query->num_rows > 0) { echo "该用户名已经存在,请输入其他用户名"; return; }
//插入数据库 $password = $_POST['password']; $hashPassword = password_hash($password, PASSWORD_DEFAULT); $insert_sql = "insert into user (roleNum,password,idNumber,userStatus) values ( 0,'$hashPassword','$idNumber',1)"; $insert_query = mysqli_query($conn, $insert_sql); $insert_id = mysqli_insert_id($conn); if ($insert_id > 0) { //插入成功 echo "添加成功:" . $idNumber; } else echo "Error: " . mysqli_error($conn); mysqli_close($conn);
//批量输出 $select_sql = "select * from user where roleNum=0 "; $select_query = mysqli_query($conn, $select_sql); while ($row = mysqli_fetch_array($select_query)) { // print_r( $row); foreach ($row as $key => $value) { if (is_int($key)){ echo $value; echo " | "; } } echo "<br>"; }