How can the use of is_numeric() and intval() functions help in preventing SQL injection vulnerabilities?

Using the is_numeric() function can help prevent SQL injection vulnerabilities by ensuring that only numeric values are passed to the database query. Additionally, using the intval() function can convert non-numeric values to integers, further safeguarding against SQL injection attacks by sanitizing user input.

$user_input = $_POST['user_input'];

if (is_numeric($user_input)) {
    $safe_input = intval($user_input);
    // Use $safe_input in your database query
} else {
    // Handle non-numeric input error
}