Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2011
    Posts
    4
    Plugin Contributions
    0

    Default sql insert query help

    Hi,

    I get catalogue information from my distributer via an xml feed.

    I have parsed the DOM and stripped out all the info I need.

    The variable $description_full contains the products full description in html form.

    The problem I have is when I execute the query:

    $query = sprintf("INSERT INTO products_description (products_name, products_description)
    VALUES ('$description_title', '$description_full')");

    if $description_full has " (double quotes) or ' (single quote) the query fails.

    How can I escape these characters?

    I've trided:
    \"$description_full\"
    $description_full = str_replace("'", "''", $description_full); (replaces single ' with two single quotes '')
    $description_full = str_replace("'", "", $description_full); (remove single ' this resulted in an empty query)
    and a bunch of other things.

    I'm not sure how I can insert the description into the database...

    Thanks in advance.

    Chuck

  2. #2
    Join Date
    Apr 2006
    Posts
    16
    Plugin Contributions
    0

    Default Re: sql insert query help

    You need to escape the string. Either of these PHP functions should do the trick:

    $description_title = mysql_real_escape_string($description_title);

 

 

Similar Threads

  1. v154 Help with a SQL Query for Query Builder
    By lindasdd in forum Managing Customers and Orders
    Replies: 2
    Last Post: 24 Mar 2016, 01:18 PM
  2. SQL query help
    By petek in forum General Questions
    Replies: 6
    Last Post: 23 May 2010, 10:57 AM
  3. How to insert products by SQL query?
    By zildjian in forum Setting Up Categories, Products, Attributes
    Replies: 6
    Last Post: 28 Feb 2009, 12:47 AM
  4. Help with a sql query
    By batteryman in forum General Questions
    Replies: 21
    Last Post: 3 Oct 2008, 11:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg