What are the potential security risks associated with storing user input in PHP?

Storing user input in PHP without proper validation and sanitization can lead to security risks such as SQL injection, cross-site scripting (XSS), and other forms of attacks. To mitigate these risks, it is important to validate and sanitize user input before storing it in a database or using it in any other way in your application.

// Validate and sanitize user input before storing it
$userInput = $_POST['user_input'];
$cleanInput = filter_var($userInput, FILTER_SANITIZE_STRING);

// Store the sanitized input in a database
// Example: 
// $stmt = $pdo->prepare("INSERT INTO table_name (column_name) VALUES (:input)");
// $stmt->bindParam(':input', $cleanInput);
// $stmt->execute();