How can PHP scripts be written to update participant numbers in a text file when a form is submitted?

To update participant numbers in a text file when a form is submitted, you can create a PHP script that reads the current participant count from the text file, increments it by one, and then writes the updated count back to the file. This can be done by first opening the file, reading the current count, incrementing it, writing the new count back to the file, and then closing the file.

<?php
$file = 'participants.txt';

// Read current participant count from file
$currentCount = file_get_contents($file);

// Increment participant count
$newCount = intval($currentCount) + 1;

// Write updated count back to file
file_put_contents($file, $newCount);

// Display success message
echo "Participant count updated successfully!";
?>