What is the best way to escape database INSERTS?
Permalink 1 user found helpful
I'm wondering what the best way to escape database inserts are. For example, with the following input:
!@#$%^&*()"'
I've tried:
The only thing though that works for this is mysql_real_escape_string() which I've read should not be used. Can anyone help? The other two methods result in a mysql error.
Thanks!
!@#$%^&*()"'
I've tried:
$db = Loader::db(); // Need to look into escaping //$grpName = $db->qstr($grpName); //$grpName = htmlspecialchars($grpName); $grpName = mysql_real_escape_string($grpName); // Create group $sql = "INSERT INTO goLabCollectionGroups VALUES('','$grpName','ENABLED','0');";
The only thing though that works for this is mysql_real_escape_string() which I've read should not be used. Can anyone help? The other two methods result in a mysql error.
Thanks!
This stuff is still vulnerable to XSS...
EDIT: See below this code is braindead.
AFAIK its adodbhttp://adodb.sourceforge.net/
...is what I do.
AFAIK its adodbhttp://adodb.sourceforge.net/
...is what I do.
Thanks!
What is the $th variable? I tried using this code block, but I got the following error:
Warning: array_map() expects parameter 1 to be a valid callback, first array member is not a valid class name or object
Warning: array_map() expects parameter 1 to be a valid callback, first array member is not a valid class name or object
I believe he meant the text helper there:
$th = Loader::helper('text');
Indeed it's a typo. @Manio is correct. Thanks @Manio.
Although the above code is totally braindead on my part.
adodb escapes for you. That above post was from when I was an idiot.
$db = Loader::db(); $db->Execute( 'INSERT INTO goLabCollectionGroup VALUES(?, ?, ?, ?)', array( '', $grpName, 'ENABLED', 0 ) );
adodb escapes for you. That above post was from when I was an idiot.
so I can insert a $_GET variable directly into a $db->Execute() ?
sweet ty :D
how would i do that same thing with an sql update?
I've found the best way is to do something like:
$db = Loader::db(); $vals = array(); $vals['column_name_a'] = "value"; $vals['column_name_b'] = "value"; $vals['column_name_c'] = "value"; $recordID = 1; $db->AutoExecute("tableName", $vals, "UPDATE", "id = $recordID");
Call to undefined method Concrete\Core\Database\Connection\Connection::AutoExecute()
Looks like the method doesn't exist - what version of C5 are you running? I do this all the time however I have to note that this is right from memory and not tested.
Have a look here at the ADODB docs:
http://phplens.com/lens/adodb/docs-adodb.htm#autoexecute...
Hope this helps.
Have a look here at the ADODB docs:
http://phplens.com/lens/adodb/docs-adodb.htm#autoexecute...
Hope this helps.
5.7.2
All the keys in the $data array, are your table columns and the values behind it the ones to be inserted. Assuming you're using 5.7.2 as you stated above that is.
thank you!
i just found this post:
https://github.com/concrete5/concrete5-5.7.0/wiki/Migration-Guide#us...
i just found this post:
https://github.com/concrete5/concrete5-5.7.0/wiki/Migration-Guide#us...
Willing to take suggestions to improve this...