php - Why does msyqli_real_escape_string() not escape multiple backslashes properly? -
given sql
update `mytable` set `mycolumn`='karla bailey-pearapppppppp\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' `id`=5619
why mysqli_real_escape_string()
not escape string properly?
trying use sql query after escaping column's value produces mysqli error:
"you have error in sql syntax; check manual corresponds mysql server version right syntax use near ''karla bailey-pearapppppppp\\\\\\\\\\\\\\\\\\\\\\\\\\\' @ line 3"
is there limit number of backslashes can escaped?
are escaping entire string? e.g.
$sql = "update .... \\\\\\\'"; $escaped = mysqli_real_escape_string($link, $sql);
if so, that's incorrect. trashing string doing that. you'll escaping '
delimit clause value. escaping should performed values you're inserting string. e.g.
$name = "miles o'brien"; // ' in name cause syntax error $bad_sql = "select '$name'"; $broken_sql = mysqli_real_escape_string($link, $bad_sql); // produces: select \'miles o\'brien\' $ok_sql = "select '" . mysqli_real_escape_string($link, $name) . "'"; // produces: select 'miles o\'brien';
Comments
Post a Comment