how to insert id from another table to a table using 1 form : i've been on this for atleast 3 days but i cant seem to get it. i have to get the user_id from the users table and insert it to the user_id of patients table using only one form. 

this is the tables i am using:
user_table: user_id is auto increment.

    ╔═════════╦══════════╦════════════════╦═══════════╗ 
    ║ user_id ║ level_id ║  email         ║  password ║ 
    ╠═════════╬══════════╬════════════════╬═══════════╣ 
    ║ 1       ║  5       ║ sasa@denva.com ║ sasadenva ║ 
    ║ 2       ║  1       ║ tony@stark.com ║ tonystark ║ 
    ╚═════════╩══════════╩════════════════╩═══════════╝

    

patients_table: patients_id is auto increment.

    +--------+---------+--------------+----------+-----------+--------+
    | pat_id | user_id | name         | address  | number    | sex    |
    | 1      | 1       | sasa mindred | manhatan | 987654329 | female |
    | 2      | 2       | tony stark   | new york | 123456789 | male   |
    +--------+---------+--------------+----------+-----------+--------+

i made the name short for the table here.



    $sql = "SELECT email FROM users WHERE email=?";
    		$stmt =mysqli_stmt_init($conn);
    		if(!mysqli_stmt_prepare($stmt, $sql)) {
    		header("Location: ../auth/register.php?error=sqlerror");
    		exit();
    
    		}else{
    			mysqli_stmt_bind_param($stmt, "s", $email);
    			mysqli_stmt_execute($stmt);
    			mysqli_stmt_store_result($stmt);
    			$resultcheck= mysqli_stmt_num_rows($stmt);
    			if($resultcheck > 0) {
    				header("Location: ../auth/register.php?error=emailtaken&last_name=".$last."&first_name=".$first."&middle_name=".$middle."&sex=".$sex."");
    				exit();
    
    			}else{
    				$sql= "INSERT INTO users (level_id, email, password, created_at) VALUES (?, ?, ?, now())";
    				$stmt = mysqli_stmt_init($conn);
    
    				if(!mysqli_stmt_prepare($stmt, $sql)){
    					header("Location: ../auth/register.php?error=sqlerror");
    					exit();
    
    				}else{
    					$hashedPwd = password_hash($password, PASSWORD_DEFAULT);
    					mysqli_stmt_bind_param($stmt, "iss", $lvl, $email, $hashedPwd);
    						
    						$user_id = mysqli_insert_id($conn);
    						$sqli = "INSERT INTO patients (user_id, last_name, first_name, middle_name, sex) VALUES ($user_id, ?, ?, ?, ?)";
    
    						$stmt = mysqli_stmt_init($conn);
    						if(!mysqli_stmt_prepare($stmt, $sql)){
    							header("Location: ../auth/register.php?error=sqlerror");
    							exit();
    
    						}else{
    							mysqli_stmt_bind_param($stmt, "ssss", $last, $first, $middle, $sex);
    							mysqli_stmt_execute($stmt);
    						}
    
    
    					mysqli_stmt_execute($stmt);
    					header("Location: ../auth/register.php?signup=success".$conn->insert_id."");
    					exit();
    				
    				}
    
    				
    			}
    		}

i expected the output to insert the user_id from the users table to the user_id of the patients table
