// 判斷數據庫是否已經存在 $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>"; }