The Joomla! Forum ™



Forum rules


Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.



Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Thu Jun 14, 2012 12:54 am 
Joomla! Intern
Joomla! Intern

Joined: Fri Feb 20, 2009 12:30 am
Posts: 80
I'm trying a simple code to update my articles. In some case I get "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'fulltext = '.....

Code:
$db = JFactory::getDbo();

$fulltext = '<p style="text-align: center;"><img src="/userfiles/image.png" alt="Deciption" title="The title" width="399" height="289" style="border: 0px; " /></p> <p>Some text, more in <a href="http://www.domain.com/page.html" title="Learn more">Learn more</a>.</p>';

$query = "UPDATE ".$db->nameQuote("#__content")." SET fulltext = ".$db->Quote($fulltext)." WHERE id = 35";

 $db->SetQuery($query);

 if($db->query()){
       echo " Success";
  } else {
      echo $db->getErrorMsg()."<br/>";
 }


Top
 Profile  
 
PostPosted: Thu Jun 14, 2012 5:11 pm 
Joomla! Intern
Joomla! Intern

Joined: Fri Feb 20, 2009 12:30 am
Posts: 80
This code seems to work, why?
Code:
$db = JFactory::getDbo();

$fulltext = '<p style="text-align: center;"><img src="/userfiles/image.png" alt="Deciption" title="The title" width="399" height="289" style="border: 0px; " /></p> <p>Some text, more in <a href="http://www.domain.com/page.html" title="Learn more">Learn more</a>.</p>';

$fulltext = $db->Quote($fulltext);

$query = "UPDATE #__content"
                . " SET `fulltext` = $fulltext"
                 . " WHERE `id` = 35";
 $db->SetQuery($query);

 if($db->query()){
       echo " Success";
  } else {
      echo $db->getErrorMsg()."<br/>";
 }


Top
 Profile  
 
PostPosted: Thu Jun 14, 2012 7:18 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri May 04, 2012 3:26 pm
Posts: 45
quote translates the html into an insertable string, and I believe protects against sql injection.

~

As a side question, are you using cli to do these updates?


Top
 Profile  
 
PostPosted: Thu Jun 14, 2012 9:34 pm 
Joomla! Intern
Joomla! Intern

Joined: Fri Feb 20, 2009 12:30 am
Posts: 80
Hellow bpc_mw!!
bpc_mw wrote:
As a side question, are you using cli to do these updates?
No, the example code I posted is inside a component.


Top
 Profile  
 
PostPosted: Fri Jun 15, 2012 5:07 pm 
Joomla! Explorer
Joomla! Explorer

Joined: Fri Nov 11, 2011 9:43 pm
Posts: 435
Location: Chicago, IL
I having the same issue migrating articles from one Joomla to another. My guess if your syntax is 100% and there are still issues you're experiencing the nightmare that is ambiguous character sets from people copy and pasting articles from various word processors.

I'll keep an eye on this as it appears we are both actively working on the same problem!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 



Who is online

Users browsing this forum: ichiro [Crawler] and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group