What are some potential security risks in the provided PHP guestbook script and how can they be mitigated?
One potential security risk in the provided PHP guestbook script is the lack of input validation, which could lead to SQL injection attacks. To mitigate this risk, all user inputs should be properly sanitized and validated before being used in database queries.
// Sanitize and validate user inputs before using them in database queries
$name = mysqli_real_escape_string($conn, $_POST['name']);
$message = mysqli_real_escape_string($conn, $_POST['message']);
// Validate input length to prevent SQL injection attacks
if(strlen($name) > 50 || strlen($message) > 255){
// Handle error
}