How can a new record be created and displayed simultaneously in PHP?

When creating a new record in PHP and displaying it simultaneously, you can first insert the record into the database and then retrieve and display the newly created record using a SELECT query. This can be achieved by executing the INSERT query to add the new record, followed by a SELECT query to fetch the record based on its unique identifier (such as an auto-incremented ID).

// Insert new record into the database
// Assuming $conn is the database connection
$sql = "INSERT INTO your_table_name (column1, column2) VALUES ('value1', 'value2')";
$result = mysqli_query($conn, $sql);

if($result) {
    // Retrieve the newly created record
    $newRecordId = mysqli_insert_id($conn);
    
    $selectSql = "SELECT * FROM your_table_name WHERE id = $newRecordId";
    $selectResult = mysqli_query($conn, $selectSql);
    
    if($selectResult && mysqli_num_rows($selectResult) > 0) {
        $newRecord = mysqli_fetch_assoc($selectResult);
        
        // Display the newly created record
        echo "New Record: " . $newRecord['column1'] . ", " . $newRecord['column2'];
    }
}