php - Slashes in MySQL tables, but using PDO and parameterized queries. Whats up? -


alright, code update database tables varying flavours of following:

$query = "   insert comment      (comment, commentdate, rating, userrid)    values      (:comment, now(), 0, :userrid )" ;  try {              $db_conn = new pdo('mysql:host='.$db_server.';dbname='.$db_name, $db_username, $db_password );    $db_conn->begintransaction();   $prep = $db_conn->prepare($query);   $prep->bindparam(':comment', $comment, pdo::param_str, 500);   $prep->bindparam(':userrid', $userrid, pdo::param_int, 20);   $prep->execute();    $db_conn->commit(); } catch (pdoexception $e)  {   $db_conn.rollback();   echo "error!: " . $e->getmessage() . "<br/>";   die(); } 

in above, comment comes in via post page. userrid being set via function call. works properly, except slashes added table.

everything i've read says in order around having slashes whenever types in apostrophe should using parameterized queries. if i'm not mistaken, i'm pretty sure that's i'm doing. missing something? can let me know i'm not doing right?

thanks in advance, michael

probably ou've magic_quotes_gpc() turned on, need this:

if (get_magic_quotes_gpc() == true) {     $comment = stripslashes($comment);     $userrid = stripslashes($userrid); } 

if you're using php 5.3+ can rid of magic quoted variables placing following lines of code on top of file:

if (get_magic_quotes_gpc() === 1) {     $_get = json_decode(stripslashes(json_encode($_get, json_hex_apos)), true);     $_post = json_decode(stripslashes(json_encode($_post, json_hex_apos)), true);     $_cookie = json_decode(stripslashes(json_encode($_cookie, json_hex_apos)), true);     $_request = json_decode(stripslashes(json_encode($_request, json_hex_apos)), true); } 

if you're running lower version of php should take @ page.


Comments

Popular posts from this blog

AbotX : How do you create a parallel crawler that stays on and can be added to at run time from new requests -

testing - Detect whether test has failed within fixture -

android - Create single AAR file from multiple modules using Gradle -