/ Published in: PHP
Function to prevent sql injection in Like queries, where the characters '_' and '%' can be dangerous.
Expand |
Embed | Plain Text
<?php function escapeLike($mysql, $data) { $escaped = $mysql->real_escape_string($data); } //Usage $dangerous_input = '%My Name'; //$mysql has to be either an instance of mysql or mysqli $query = "SELECT * FROM tbl WHERE field LIKE '" . escapeLike($mysql, $dangerous_input) . "%'"; ?>
You need to login to post a comment.
