500 You have an error in your SQL syntax MariaDB

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
cmf4
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Wed Jun 22, 2022 6:37 pm

500 You have an error in your SQL syntax MariaDB

Post by cmf4 » Wed Jun 22, 2022 6:52 pm

I created a module that fetches the content in the "content" table of the "introtext" field in the joomla database, so far so good if I try to update the same content or modify it with this:

$ query = $ db-> getQuery (true );

$ fields = array ($ db-> quoteName ('intotext'). '='. $ updtext); $ conditions = array ($ db-> quoteName ('id'). '='. $ article_id);

$ query-> update ($ db-> quoteName ('#__ content')) -> set ($ fields) -> where ($ conditions);

echo $ db-> replacePrefix ((string) $ query);

$ db-> setQuery ($ query);

displays this error:

"500 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '\'<p>{loadposition tabgpx}</p><table style=\"height: 129px; width: 325px; f...' at line 2" is not valid header value ........

i tried anyway, apex, quotes and addslash but nothing to do.

can you help me?

gws
Joomla! Champion
Joomla! Champion
Posts: 5883
Joined: Tue Aug 23, 2005 1:56 pm
Location: South coast, UK
Contact:

Re: 500 You have an error in your SQL syntax MariaDB

Post by gws » Wed Jun 22, 2022 7:01 pm

$ fields = array ($ db-> quoteName ('intotext'). '='. $ updtext); $ conditions = array ($ db-> quoteName ('id'). '='. $ article_id);
Should intotext not be introtext?

cmf4
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Wed Jun 22, 2022 6:37 pm

Re: 500 You have an error in your SQL syntax MariaDB

Post by cmf4 » Wed Jun 22, 2022 7:10 pm

gws wrote:
Wed Jun 22, 2022 7:01 pm
$ fields = array ($ db-> quoteName ('intotext'). '='. $ updtext); $ conditions = array ($ db-> quoteName ('id'). '='. $ article_id);
Should intotext not be introtext?
Sorry

I wrote wrong, in the code it is right, and it works if I don't insert some HTML code, but I need to insert some html code like the one that is already in the "intotext" field

User avatar
pe7er
Joomla! Master
Joomla! Master
Posts: 24927
Joined: Thu Aug 18, 2005 8:55 pm
Location: Nijmegen, Netherlands
Contact:

Re: 500 You have an error in your SQL syntax MariaDB

Post by pe7er » Thu Jun 23, 2022 7:02 am

Welcome to Joomla forum!

You need to quote the string to get it work.

Code: Select all

$updtext
should be

Code: Select all

$db->quote($updtext)
See: https://docs.joomla.org/Inserting,_Upda ... _JDatabase

For safety you could force numbers to be integers, so change

Code: Select all

 $article_id
to

Code: Select all

(int) $article_id
Kind Regards,
Peter Martin, Global Moderator
Company website: https://db8.nl/en/ - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com

cmf4
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Wed Jun 22, 2022 6:37 pm

Re: 500 You have an error in your SQL syntax MariaDB

Post by cmf4 » Thu Jun 23, 2022 8:36 am

pe7er wrote:
Thu Jun 23, 2022 7:02 am
Welcome to Joomla forum!

You need to quote the string to get it work.

Code: Select all

$updtext
should be

Code: Select all

$db->quote($updtext)
See: https://docs.joomla.org/Inserting,_Upda ... _JDatabase

For safety you could force numbers to be integers, so change

Code: Select all

 $article_id
to

Code: Select all

(int) $article_id
i have done all these things already, look at the code in the first post, in fact everything works if i don't try to write in the html code field, that's the problem.

cmf4
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Wed Jun 22, 2022 6:37 pm

Re: 500 You have an error in your SQL syntax MariaDB

Post by cmf4 » Sun Jun 26, 2022 7:41 am

If there is no suggestion or it is not possible, I can solve the problem in a better way if the additional fields in a form work for me as requested in this topic

viewtopic.php?f=808&t=994610


Locked

Return to “Joomla! 3.x Coding”