mysql - Having weird trouble using a PHP post function -
so, i've got pretty basic code can't work quite right. i'm using ezsql class (http://justinvincent.com/ezsql), that's working fine. works fine, except when try use sanitize function (get_post). i'm using 2 other functions, sanitizestring , sanitizemysql when call function get_post. if $_post data right sql table, works fine. it's when go thru post function breaks. here's posting bit:
if (isset($_post['username']) && isset($_post['password'])) { $username = get_post('username'); $password = get_post('password'); $db->query("insert users values ('$username', '$password')"); } like said, i'm using class (that's $db->query stuff about), that's working perfectly. if change code this:
if (isset($_post['username']) && isset($_post['password'])) { $username = $_post['username']; $password = $_post['password']; $db->query("insert users values ('$username', '$password')"); } it works fine. here 3 functions i'm using sanitizing:
// sanitize functions function sanitizestring($var) { if (get_magic_quotes_gpc()) $var = stripslashes($var); $var = htmlentities($var); $var = strip_tags($var); return $var; } function sanitizemysql($var) { $var = mysql_real_escape_string($var); $var = sanitizestring($var); return $var; } function get_post($var) { return sanitizemysql($_post['$var']); } i've tried changing get_post function contain mysql_real_escape_string return, , doesn't work. also, guess should clarify happens when try use get_post function. appears create new row in table, empty cells. hope guys can shed light on i'm doing wrong! i'm pretty experienced front-end developer, i'm kinda learning ropes server-side stuff. :)
ninjaedit: found question are these 2 functions overkill sanitization? helpful in making sanitize functions better, doesn't me why mine aren't working in first place.
why did put ' around $var ?
in function get_post should return sanitizemysql($_post[$var]);
you should use prepared statement escapes character you
Comments
Post a Comment