• 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

    • Just saw a news report of a Waymo driving into a flooded road.
    • Password Safe 3.72.0 by Razvan Serea Password Safe is a password database utility. Like many other such products, commercial and otherwise, it stores your passwords in an encrypted file, allowing you to remember only one password (the "safe combination"), instead of all the username/password combinations that you use. Once stored, your user names and passwords are just a few clicks away. Using Password Safe you can organize your passwords using your own customizable references—for example, by user ID, category, web site, or location. You can choose to store all your passwords in a single encrypted master password list (an encrypted password database), or use multiple databases to further organize your passwords (work and home, for example). And with its intuitive interface you will be up and running in minutes. PasswordSafe was originally designed by the renowned security technologist Bruce Schneier and released as a free utility application. Password Safe 3.72.0 changelog: Fixed bugs Improved font scale handling - should resolve font size issues on high resolution displays. GH1749 In the Master Password Setup window, "Show Master Password" is no longer truncated on some displays. GH1092, SF1595 Size and position of main window is now correctly restored on scaled displays. SF1630 Keep password expiry date when both password and password expiry are changed; don't clear a non-recurring expiry when the password's changed. SF1628 Custom values can now be copied to the clipboard in read-only mode via Ctrl-C and right-click->Copy Value. New features GH1196 Dark display mode support: Password Safe now supports the system display mode, as well as setting the mode directly via Manage->Options->Display->Display Mode. This change also updates the general "look & feel" of the app to the current Windows theme. Known limitations: The Date picker and keyboard shortcut controls do not switch to dark theme The Customize Toolbar dialog does not switch to dark theme Custom Field support has been added to the more advanced features: Filters XML and Text import and export Comparison, Sync and Merge databases SF938 Custom field values may now be selected by name and copied via a "Copy Custom Field Value..." submenu in the entry context popup menu. SF936 Notes and Custom fields layout now overlap, selectable by tabs, resulting in a more compact and less cluttered layout. SF935 Autotype: Specifying '\v{name}' in the autotype text will cause the corresponding value to be autotyped. Download: PasswordSafe 64-bit | Portable 64-bit | ~20.0 MB (Open Source) Download: PasswordSafe 32-bit | Portable 32-bit View: PasswordSafe Website | Quickstart Guide | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Google DeepMind published a document on June 18, 2026, that may be the most consequential admission yet from a frontier AI lab: alignment training alone cannot guarantee that AI agents will remain under human control, so structural containment must be built before more capable models arrive.............. https://www.techtimes.com/articles/318758/20260620/google-deepmind-ai-control-roadmap-when-alignment-fails-defense-depth-takes-over.htm  
    • I've got a SoundBlasterX G6 that I use in my streaming setup. Sounds great to me and I've had zero issues with the ancient software package so far in Win11. That G6 has 7.1, Dolby, fully working SPDIF and since it's a USB device it's outside of my rig so I don't have to worry about EMF distortion. Looks like for now this is a pass for me as I think I have better hardware....
    • How do you connect 5.1 Speakers to this thing?
  • Recent Achievements

    • Dedicated
      Almohandis earned a badge
      Dedicated
    • Dedicated
      JuvenileDelinquent earned a badge
      Dedicated
    • First Post
      DrWankel earned a badge
      First Post
    • Reacting Well
      DrWankel earned a badge
      Reacting Well
    • Week One Done
      Supreme Spray LV earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      503
    2. 2
      +Edouard
      170
    3. 3
      PsYcHoKiLLa
      88
    4. 4
      Steven P.
      75
    5. 5
      Michael Scrip
      74
  • Tell a friend

    Love Neowin? Tell a friend!