I am trying to store a sql query string in a MySQL field, and I am having problems correctly escaping the string.
If I insert the following string into the sql varchar field of the test table, using phpMyAdmin:
INSERT INTO `test` SET `test`.`sql`='{$_POST['sql']}'
and then export it using phpMyAdmin, it gives me the following sql query:
INSERT INTO `test`.`test` (`sql`)
VALUES ('INSERT INTO `test` SET `test`.`sql`=''{$_POST[''sql'']}''');
If I want my own php script to do this, with what function do I escape:
INSERT INTO `test` SET `test`.`sql`='{$_POST['sql']}'
to make it look like:
'INSERT INTO `test` SET `test`.`sql`=''{$_POST[''sql'']}'''
I have a large number of sql queries I need to store for retrieval.
What is phpMyAdmin doing to the original string to create:
INSERT INTO `test`.`test` (`sql`)
VALUES ('INSERT INTO `test` SET `test`.`sql`=''{$_POST[''sql'']}''');
What is the function xyz where:
$a = "INSERT INTO `test` SET `test`.`sql`='{$_POST['sql']}'";
$b = "INSERT INTO `test`.`test` (`sql`)
VALUES ('INSERT INTO `test` SET `test`.`sql`=''{$_POST[''sql'']}''')";
$b = xyz($a);
mysql_real_escape_string($_POST['sql'])- this handle a lot of escaping itself aside from the fact of security and injection.testSETtest.sql='" . mysql_real_escape_string($_POST['sql']) . "'"; $encoded2 = base64_encode ($sql); $decoded2 = base64_decode ($encoded2); echo $decoded2; // $decoded2 does not = $sql, I don't understand