0) { echo "Something went wrong. Please generate again!"; } else { $sql2 = mysqli_query($conn, "INSERT INTO url (full_url, shorten_url, clicks) VALUES ('{$full_url}', '{$ran_url}', '0')"); if ($sql2) { $link_id = mysqli_insert_id($conn); // Get the ID of the newly inserted row if (!isset($_SESSION['shortened_links'])) { $_SESSION['shortened_links'] = array(); } $_SESSION['shortened_links'][] = $link_id; // Store the link ID in session $shorten_url = $ran_url; echo $shorten_url; } } } else { echo "$full_url - This is not a valid URL!"; } ?>