How can the entire dynamically changing part of the URL be saved as $parentID in the database for PHP usage?

To save the dynamically changing part of the URL as $parentID in the database for PHP usage, you can use PHP's $_SERVER['REQUEST_URI'] to get the current URL, then extract the dynamic part using regular expressions or string manipulation. Once you have the $parentID extracted, you can save it in the database for later use.

// Get the current URL
$currentURL = $_SERVER['REQUEST_URI'];

// Extract the dynamically changing part using regular expressions
preg_match('/\/(\d+)\/?$/', $currentURL, $matches);
$parentID = $matches[1];

// Save $parentID in the database
// Assuming you have a database connection established
// Replace 'your_table_name' with your actual table name
$query = "INSERT INTO your_table_name (parent_id) VALUES ('$parentID')";
$result = mysqli_query($connection, $query);

if($result){
    echo "Parent ID saved successfully!";
} else {
    echo "Error saving parent ID: " . mysqli_error($connection);
}