What is the issue with storing an RGB code in a database using PHP and how can it be resolved?
Issue: Storing an RGB code in a database using PHP can lead to potential SQL injection vulnerabilities if the input is not properly sanitized. To resolve this issue, it is important to use prepared statements to prevent SQL injection attacks.
// Using prepared statements to store RGB code in a database
$rgbCode = "#ff0000"; // Example RGB code
// Prepare a SQL statement
$stmt = $pdo->prepare("INSERT INTO colors (rgb_code) VALUES (:rgb_code)");
// Bind parameters
$stmt->bindParam(':rgb_code', $rgbCode);
// Execute the statement
$stmt->execute();