• 0

Field wont insert into the database


Question

Having trouble inserting some data into a database, basically i'm scraping data from an RSS feed and looping through each entry and inserting it into a database but when it gets to the 'content' field it fails, but there is no errors, it just wont insert.. if i remove the content field then it inserts just fine so i think thats the culprit.


$RSS_DOC = simpleXML_load_file($feed_url);


foreach($RSS_DOC->channel->item as $RSSitem) {

	$content = $RSSitem->description;

	$item_insert_sql = "INSERT INTO default_posts(content) VALUES ('$content')";

	$insert_item = mysql_query($item_insert_sql, $db);

}

$RSSitem->description would be:

<description><![CDATA[Madonna celebrated Yom Kippur in New York City on Tuesday (25.09.12). <BR>
The 'Celebration' singer is a devotee of Jewish offshoot Kabbalah and joined with other followers of the religion to celebrate the Day of Atonement, the holiest day in the calendar for Jewish people.<BR>
Madonna, 54, arrived at the city's Park Avenue Armory wearing a bright purple sweat suit with the number 86 on them and a hat with the word 'Vogue' written on it. <BR>
A source told the New York Post newspaper: "Madonna was the last to arrive, and it seemed like they were holding up the ceremony to wait for her. <BR>
"She came through a back entrance with her daughter, Lourdes, and was seated in the front row. Once she was seated, it could begin. All the men were in white but Madonna had a loud track suit on. Also there was her younger boyfriend [Brahim Zaibat], who arrived wearing cream." <BR>
While her entrance may have caused a stir, the 'Hung Up' singer certainly focused during the service, and appeared oblivious to those around her, including fashion designer Donna Karan, who was seated nearby. <BR>
The witness added: "[Madonna] definitely set herself apart from everyone else. She is like the queen of Kabbalah."<BR>
A statement on the Kabbalah website explains the religious day's significance, saying "[During] Yom Kippur, we sit on the throne with Binah and remove the fog in our lives for the entire year to come." <BR>
Earlier this week, Madonna was forced to clarify comments she made at a concert on Monday (24.09.12) in Washington, where she referred to the US president as a "black Muslim," despite him being openly Christian.<BR>
Madonna said she was "being ironic," adding: "Yes, I know Obama is not a Muslim, though I know that plenty of people in this country think he is."]]></description>

if i $echo description; it prints correct so i know it's pulling the data but why wont it go into to the DB? the $content field is set to LONGTEXT.

Does it have anything to do with <![CDATA[ ?

Any suggestions?

sorry about double post neowin borked

Link to comment
https://www.neowin.net/forum/topic/1108587-field-wont-insert-into-the-database/
Share on other sites

1 answer to this question

Recommended Posts

  • 0

You have forgotten the rule zero - to escape text data before passing to MySQL. Your query becomes malformed like this:

INSERT INTO default_posts(content) VALUES ('<description><![CDATA[Madonna celebrated Yom Kippur in New York City on Tuesday (25.09.12). <BR> The ');

SQL thinks your text data ends at the first single quote it sees. However, it then finds more text that totally isn't valid SQL statement. And so INSERT fails. Of course, if you don't check for errors, it won't show any.

Solution (partly):

A) $content = mysql_real_escape_string($RSSitem->description);

B) Use mysqli and its parameter binding/binary transfer. Escape text data anyway (with mysqli_real_escape_string(), accordingly) - to avoid problems outputting it later.

This topic is now closed to further replies.
  • Posts

    • Google Gemini has been failing for users across the United States, Europe, and Asia since early Wednesday morning, June 10, 2026, and more than six hours into the incident Google has yet to declare a fix............. https://www.techtimes.com/articles/318152/20260610/google-gemini-outage-tops-six-hours-errors-1076-1099-worldwideflash-lite-still-answers.htm
    • Fun fact: There are more Warhammer 40k games than there are stars in the universe.
    • laughing is tedious. Elephants really are laughing lazy, y'all..
    • Agreed. And this is a great discount offer! It's a shame that there's no discount offer option for people who would be fine subscribing for a year-long term, but pay monthly.
    • A Warhammer 40K racing game and a chess roguelike are free to claim on the Epic Games Store by Pulasthi Ariyasinghe The Epic Games Store has returned to its standard giveaway procedures after weeks of mystery freebies. The latest drop is replacing last week's Rogue Waters and Songs of Conquest games and has brought in a double giveaway offering Warhammer 40K Speed Freeks and The Ouroboros King. As always, the game is yours to add permanently to your Epic Games Store library within the next seven days. From the duo, Warhammer 40K Speed Freeks lands from developer Caged Element, and it's a racing game that was only released last year. The title has you piloting Ork buggies, tanks, and aircraft modeled after the popular tabletop miniatures. The focus is on multiplayer mayhem, offering multiple game modes that have you fighting other players as everyone tries to survive and get across finish lines or destroy mechs. Crossplay support between PC and consoles has now arrived as part of a free update, too, giving a boost to matchmaking times for this multiplayer-focused title. If racing carnage isn't your thing, then The Ouroboros King offers tactics. The indie title is a mashup of chess and standard roguelike experience, letting players create their own armies to defeat an enemy faction, all on the familiar checkered board. There is a procedurally generated map, pieces with special abilities, relics that bend the game's rules to make overpowered builds, and more. The newly available Warhammer 40K Speed Freeks and The Ouroboros King giveaways on the Epic Games Store are set to run until June 11, giving PC gamers seven days to claim the latest offer. Once this closes out, a new freebie will take its place on the same day. Don't forget that mobile gamers can check out the Epic Game Store's weekly giveaways on Android and iOS to grab a freebie there as well.
  • Recent Achievements

    • Week One Done
      FBSPL earned a badge
      Week One Done
    • One Year In
      Jim Dugan earned a badge
      One Year In
    • One Month Later
      Tommi118 earned a badge
      One Month Later
    • One Month Later
      sjbousquet earned a badge
      One Month Later
    • Week One Done
      sjbousquet earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      486
    2. 2
      PsYcHoKiLLa
      197
    3. 3
      +Edouard
      155
    4. 4
      Steven P.
      83
    5. 5
      ATLien_0
      69
  • Tell a friend

    Love Neowin? Tell a friend!