How can I generate an activation link when inserting an article into a MySQL database using PHP?

To generate an activation link when inserting an article into a MySQL database using PHP, you can create a unique activation code using functions like md5() or uniqid(). This code can be stored in the database along with the article information. When displaying the article, you can include this activation code in the URL as a parameter and use it to activate the article when the link is clicked.

// Generate activation code
$activationCode = md5(uniqid(rand(), true));

// Insert article and activation code into database
$stmt = $pdo->prepare("INSERT INTO articles (title, content, activation_code) VALUES (:title, :content, :activationCode)");
$stmt->bindParam(':title', $title);
$stmt->bindParam(':content', $content);
$stmt->bindParam(':activationCode', $activationCode);
$stmt->execute();

// Display article with activation link
echo "<a href='activate.php?code=$activationCode'>Activate Article</a>";