Php 如何插入已连接用户的数据库ID?

Php 如何插入已连接用户的数据库ID?,php,mysql,Php,Mysql,我正在尝试将连接的当前用户名的id插入数据库,如何从查询中获取我的用户名id? 我正在尝试将新行插入数据库,需要连接的用户的id <?php require 'connect.inc.php'; require 'core.inc.php'; ?> <?php $username = ""; if(isset($_POST['username'])&&isset($_POST['password'])){

我正在尝试将连接的当前用户名的id插入数据库,如何从查询中获取我的用户名id? 我正在尝试将新行插入数据库,需要连接的用户的id

<?php
     require 'connect.inc.php';
     require 'core.inc.php';
    ?>
    <?php

    $username = "";
    if(isset($_POST['username'])&&isset($_POST['password'])){
        $username = $_POST['username'];
        $password = $_POST['password'];
        if(!empty($username)&&!empty($password)){

        $query = "SELECT `id` FROM `auth_user` WHERE `username`='$username' AND `password`='$password'";
        echo $query;
        if($query_run = mysqli_query($connect, $query)){
            $query_num_rows = mysqli_num_rows( $query_run);

        if($query_num_rows==0){
            echo 'Invalid username/password combination.';
        }else if ($query_num_rows==1){
         $_SESSION['username']=$username; 
         $_SESSION['password']=$password;
         $_SESSION['id']=$query_num_rows;

         header('Location: main.php');

        }

        }

        }else{
            echo 'You must supply a username and password.';

        }

    }

    if(isset($_POST["Submit"])){
        if(isset($_POST["ch1"])){
        setcookie("unm",$_POST["username"],time()+3600);
        setcookie("pwd",$_POST["password"],time()+3600);
        }
        }
    ?>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
    Username: <input type="text" name="username"><br><br>
    Password: <input type="password" name="password"><br><br>
    <input type="submit" value="Login"><br><br>
    <input type= "checkbox" name="ch1" value="ch" />Remember username and password <br><br>
    <a href="removename_password.php">Remove username and password</a><br><br>


与此类似,如果ID存储所选记录的ID:

if ( $row = mysql_fetch_assoc( $query_run )) {

    $userID = $row["ID"];

}
根据我得到的: 假设您有一个名为session_logged_的列,将当前日期和时间存储在unix时间戳中,然后
$query=“从
auth_user
中选择
id
,其中
username
=“$username”和
password
=“$password”按会话顺序登录描述限制0,1”

为什么要将当前连接的用户插入数据库?(很明显,它肯定已经存在了)。我正在尝试在数据库中插入新行,所以我需要连接到我的系统并创建新数据的用户的id,以便将他的id插入到具有新数据的新行。