How can the SQL syntax error near 'DELET FROM user' be resolved in the given PHP code?
The SQL syntax error near 'DELET FROM user' can be resolved by correcting the typo in the SQL query. The keyword 'DELET' should be changed to 'DELETE' to properly execute the query. Additionally, it's important to ensure that the table name 'user' is correct and that the query is properly formatted.
<?php
// Corrected SQL query with 'DELETE' instead of 'DELET'
$sql = "DELETE FROM user WHERE id = 123";
// Execute the query using mysqli_query or PDO
$result = mysqli_query($conn, $sql);
// Check if the query was successful
if($result) {
echo "Record deleted successfully";
} else {
echo "Error deleting record: " . mysqli_error($conn);
}
?>