显示输入文本到数据库的ID

I'm fairly new to stack overflow. i am creating a site were you type text in to 2 text boxes and it sends it to a database. i need it then to tell me what the id of that was save it as a session and then upload it to another database. sounds confusing. but I'm stuck of one part. its viewing the result thats from just that user. i have tried just showing the the last id of the last uploaded but it can be very unreliable if multiple people are trying to upload data and know there exact session. I'm also having trouble linking the session with the id. below is the code for the forum saving to the database. I'm pretty confident with sending the id of that users inputed data to another database. I'm just stuck on finding that users inputed texts id and creating a session holding the id number

<?php
header("Location:myscorenum.php");
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "score";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
session_start();

if (isset($_SESSION['username'])){
$username = $_SESSION['username'];
echo "working";
}else{
//3.2 When the user visits the page first time, simple login form will be displayed.
}

$value = $_POST['name'];
$value1 = $_POST['description'];



$sql = "INSERT INTO all_scores (name, description) VALUES ('$value','$value1')";



if ($conn->query($sql) === TRUE) {
    echo "<a href=https://twitter.com/angela_bradley>My Twitter</a>";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>

ill have the processing to inset to another database in another file. I'm confident with uploading a specific session.

any questions don't hesitate to message me. thanks for your kind help.

</div>

You can use this:

mysqli::$insert_id -- mysqli_insert_id — Returns the auto generated id used in the last query

Like: echo $conn->insert_id;

Since you call it on $conn which is a mysqli instance that already has a connection, it will return your last inserted id, irregardless of other activities on the db (other queries do not affect the correctness of the output)

I edited my answer. This is the final part of your code and I've just added one line of code to it. Look if this is what you're looking for. If this isn't working than make sure your database id field is AI.

 if ($conn->query($sql) === TRUE) {
    $id=$conn->insert_id; //this is where you get the last inserted id.
        echo "<a href=https://twitter.com/angela_bradley>My Twitter</a>";
    } else {
        echo "Error: " . $sql . "<br>" . $conn->error;
    }

    $conn->close();
    ?>

To use a session and set the ->insert_id to a session variable and use it in any other page, you can do this:

if ($conn->query($sql) === TRUE) {
session_start();
$_SESSION['id']=$conn->insert_id;

        echo "<a href=https://twitter.com/angela_bradley>My Twitter</a>";
    } else {
        echo "Error: " . $sql . "<br>" . $conn->error;
    }

    $conn->close();
    ?>

and now in any other page do this to retrieve the session variable:

session_start();
$id=$_SESSION['id'];

here you go and you get the id. Are you still confused?