• 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

    • Internet Download Manager (IDM) 6.43 Build 2 by Razvan Serea Internet Download Manager (IDM) is a tool to increase download speeds by up to 8 times due to its smart dynamic file segmentation technology. Unlike other download managers and accelerators, Internet Download Manager segments downloaded files dynamically during download process, and it reuses available connections without additional connect and login stages to achieve the best possible acceleration performance. Comprehensive error recovery and resume capability will restart broken or interrupted downloads due to lost connections, network problems, computer shutdowns, or unexpected power outages. All popular browsers are supported IDM integrates seamlessly into Google Chrome, FireFox, Microsoft Edge, Opera, Safari, Internet Explorer, Maxthon and all other popular browsers to automatically handle your downloads. You can also drag and drop files, or use Internet Download Manager from command line. The program supports proxy servers, ftp and http protocols, firewalls, redirects, cookies, authorization, MP3 audio and video content processing. IDM includes web site spider and grabber IDM downloads all required files that are specified with filters from web sites, for example all pictures from a web site, or subsets of web sites, or complete web sites for offline browsing. It's possible to schedule multiple grabber projects to run them once at a specified time, stop them at a specified time, or run periodically to synchronize changes. Easy downloading with one click When you click on a download link in a browser, IDM will take over the download and accelerate it. You don't need to do anything special, just browse the Internet as you usually do. IDM will catch your downloads and accelerate them. IDM supports HTTP, FTP, HTTPS and MMS protocols. Changes in Internet Download Manager 6.43 Build 2: Resolved the problem that caused a "403 Forbidden" error when downloading some files Fixed a problem causing IDM download panel not to appear on some websites Fixed a bug that caused a crash when converting some TS files to MP4 Download: Internet Download Manager 6.43 Build 2 | 11.9 MB (Shareware) Links: Internet Download Manager Website | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • It's in Experimental (26H2). Settings->Windows Update->Windows Insider Program. Then a) select Experimental, b) below that, select "Advanced Options" (where you will see the three options for "Experimental" builds -> select 26H2 (name change from 25H2 is rolling; so might be 25H2)
    • I am not a US citizen nor a Trump fan. Respect to both left and right. But I will, for the sake of fun, predict something for my own. There will come a day when the US and China will collide like titans ( over Taiwan or anything else ). Then, on that day, some people in this comment section will realize how good an idea it was to become independent in areas like that. ( Or atleast try )
    • Microsoft Edge gets tons of security features, including AI model that can see your screen by Usama Jawad Microsoft Edge may not be the most popular browser out there, but it does receive quite frequent updates that sometimes bring surprising new features and axe others that are not as popular. Now, Microsoft has detailed some of the new security enhancements that it has introduced in Edge for Business, typically used by commercial customers. Microsoft has emphasized that security features are baked into Edge for Business and offer native integration with security and governance tools like Defender and Purview. Browser sessions are governed by default on managed devices but can also be governed through dedicated work profiles on unmanaged devices. An important aspect in this area is controlling the use of shadow AI. We have talked about this before, but it essentially restricts employees from using unsanctioned AI apps through data loss prevention (DLP) policies, with Edge redirecting them to trusted AI services like Microsoft 365 Copilot. This feature, available as a pay-as-you-go (PAYG) license, ensures that confidential data never exits AI boundaries set by your organization in Purview. Additionally, Microsoft also has strong DLP policies for contractors. Contractors leveraging a Entra ID-joined work profile provisioned by their contracting company on a device managed by their actual employer can be restricted from downloading files locally. In such scenarios, the file is saved on the contracting firm's OneDrive rather than being downloaded locally. Another useful Edge security feature disallows copying and pasting from unmanaged locations and apps. Similarly, DLP policies can be configured at a granular level to restrict screenshots or downloading of files from certain locations. In the same vein, IT admins can block the installation of extensions, hosted apps, themes and scripts, and control if users can install extensions from external locations. They can also enable the installation of specific extensions and allow users to request access to certain extensions, so that they can be managed on a case-by-case basis. Finally, Edge for Business now has an on-device AI model that uses computer vision to see what's on your screen and block potentially malicious content immediately. This does not rely on site reputation, as it simply monitors what is being displayed on your screen, which means that it is effective against malicious content that takes over your screen and employs scareware tactics. Since this is an on-device AI model, it does use your system's resources, so it's enabled by default only on devices with at least 2GB of RAM and four CPU cores. You can find more details in the Microsoft Mechanics video here.
  • Recent Achievements

    • Dedicated
      Zeynel earned a badge
      Dedicated
    • One Month Later
      JKR earned a badge
      One Month Later
    • Dedicated
      Asgardi earned a badge
      Dedicated
    • Conversation Starter
      jessse3334 earned a badge
      Conversation Starter
    • Reacting Well
      JuvenileDelinquent earned a badge
      Reacting Well
  • Popular Contributors

    1. 1
      +primortal
      495
    2. 2
      +Edouard
      247
    3. 3
      PsYcHoKiLLa
      154
    4. 4
      Steven P.
      86
    5. 5
      macoman
      65
  • Tell a friend

    Love Neowin? Tell a friend!