To insert something to database you should send data with post request, get this data from request and save it. You created code which will insert last row of your loop on post request.
You should create form for each of your previous trip and add hidden input fields to have the opportunity to get them on post request.
<?php
// Handling request and saving to database should not be in template,
// but for the simplicity of the example I will leave it here.
if( isset( $_POST['rebook'] ) ) {
// Get value from $_POST array secure way after sanitization
$destination = filter_input( INPUT_POST, 'destination', FILTER_SANITIZE_STRING );
$departing = filter_input( INPUT_POST, 'departing', FILTER_SANITIZE_STRING );
$table = $wpdb->prefix . "table_name";
$wpdb->insert(
$table,
array(
'your_destination' => $destination,
'your_departing' => $departing
)
);
}
?>
<?php $rows = array(); // Get data from database ?>
<?php foreach ( $rows as $row ): // Iterate over data ?>
<?php
// Create form for each previous trip to that
// there would be an opportunity to save each
?>
<form method="post" action="">
<div> Previous Trip from:
<?php echo $row->your_departing .' to : '.$row->your_destination; ?>
<?php // Create hidden fields to send 'departing' and 'destination' with $_POST data ?>
<input type="hidden" name="departing" value="<?php esc_attr( $row->your_departing ); ?>">
<input type="hidden" name="destination" value="<?php esc_attr( $row->your_destination ); ?>">
<button type="submit" name="rebook" class="signupbtn">REBOOK</button>
</div>
</form>
<?php endforeach; ?>