1、输入变量检查
if(empty($id) || !is_numeric($id))
|| !preg_match(“/^[a-zA-Z0-9]{4,}$/”, $username)

2、转义特殊字符
addslashes($username)
mysqli_real_escape_string($db, $username)

3、预编译机制