The MU forums have moved to WordPress.org

Stripslashes and Addslashes (2 posts)

  1. suleiman
    Member
    Posted 17 years ago #

    I have code to the following effect:

    foreach ($post_category as $key => $value) {
    $playground = get_category($value);
    $accat = $playground->cat_name;
    $wpdb->query(...)

    I thought adding this code: $post_category = addslashes($post_category);

    Would allow me to enter data into the table even when the $post_category contained data that had apostrophes and the like in it. But this isn't happening. Does anyone know why?

  2. suleiman
    Member
    Posted 17 years ago #

    It turns out it was better to add the "addslashes" directly into the $wpdb->query command instead of trying to set a variable as such.

    The net (working) result looked like this:

    $wpdb->query(
    "INSERT IGNORE INTO wp_global_posts
    (ID, public, blog_id, title, category, timestamp, post_id)
    VALUES
    ('', $public_blog, $blog_id, '$post_title', '".addslashes(__($accat))."', '$post_date', '$p_id')");
    }

    P.S. Thanks to The Fray who helped me through these embattled past five hours.

About this Topic

  • Started 17 years ago by suleiman
  • Latest reply from suleiman