0

I'm doing an INSERT into a wordpress table and anything with an apostrophe is coming out

It\'s true

I tried using htmlspecialchars but I'm still getting the backslash.

Is there any way to write it so that the user sees

It's true

While the table in the database sees:

It\'s true

Below is my insert code:

global $wpdb;
                $table =    'wp_nc_location';
                $data =     array(
                            'name' => $name,
                            'street_no' => $street_number,
                            'street_name' => $street_name,
                            'city' => $city,
                            'province_state' => $province_state,
                            'postal_code' => $postal,
                            'country' => $country
                            ); 
                $format =   array(
                            '%s',
                            '%s',
                            '%s',
                            '%s',
                            '%s',
                            '%s'
                            );
                $wpdb->insert( $table, $data, $format);

2 Answers 2

2

When you retrieve the data make sure to call stripslashes, or stripslashes_deep if it's an array.

$name = stripslashes($name);
0

How are you writing and reading data exactly?

Are you using $wpdb->insert() method? Which you should be doing, it takes care of escaping.

1
  • I am using $wpdb->insert()...I wonder why it isn't removing the slashes? I'll post my actual code... Commented Aug 20, 2011 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.