Well here is a wierd thing. At the moment I’m trying to write my first WordPress plugin (for an image gallery). Everthing I posted to the database seemed to be getting wrapped with tags. After 20 minutes of tearing my hair out, here is why:
I was using the following code:
$gallery_name = $_POST['gallery_name'];
$gallery_name = escape($gallery_name);
$result = $wpdb->query("INSERT INTO...;
This saved say ‘
‘ to the database when all I wanted was ‘monkey’ – the answer? Well i should have been using:
$gallery_name = $wpdb->escape($gallery_name);
Who would have thought so stupidly simple and such a bugger to find. Still the most useful bit of PHP I know is:
'); print_r($_POST); echo('
After all if you are going to tear your hair out it is better to be safe than sorry.