Hello all.
I have a small db, that has news.
I want to update the field "content" to add the phraze "<br>Aproved by Admin" for every row in the database.
A better explanation, i have table news, with 1 table that is defined : create table news (id int, creator char(10), content char(255));
and for example i have 2 rows:

insert into news values (1,"admin","test1");
insert into news values (1,"nonadmin","test2");

i want to update all the values of the content be current content+"<br>Aproved by Admin"
How can i do that ?
Thanks in advance.

Dani AI

Generated

The string‑concatenation fix suggested by and echoed by does the job (and confirmed it ran). A few practical points and safer alternatives to avoid surprises on a live dataset:

First, watch the column type and length. A CHAR(255) column is fixed‑length and can lead to trailing spaces and silent truncation if the new content exceeds the column size (behavior depends on SQL mode). A quick check for long rows is useful:

SELECT id, creator, LENGTH(content) AS len, content
FROM news
ORDER BY len DESC
LIMIT 10;

For safer data modeling, avoid stuffing administrative notes into the main content field. Adding explicit audit/approval columns or a separate notes table keeps content clean and makes reversions easy. Example changes:

ALTER TABLE news
  ADD COLUMN approved_by VARCHAR(64) NULL,
  ADD COLUMN approved_at DATETIME NULL;

Then set the new fields (no HTML injected into content):

UPDATE news
SET approved_by = 'Admin', approved_at = NOW()
WHERE approved_by IS NULL;

Always back up and test first. A quick snapshot copy is simple to create:

CREATE TABLE news_backup AS SELECT * FROM news;

When appending markup directly to content, prefer '<br />' (XHTML style) and confirm how the application renders stored HTML — many frameworks escape output, so literal &lt;br&gt; may appear instead of a line break. Also note the phrase in the thread used “Aproved” (missing a ‘p’) — check spelling. Finally, consider XSS risks: sanitization or storing structured metadata (approved flag, admin note) is usually safer than embedding HTML into content.

Recommended Answers

All 6 Replies

Try this :

update news set content=concat(content,' <br>Aproved by Admin');

Ty vm =)

Hello all.

I want to update the field "content" to add the phraze "<br>Aproved by Admin" for every row in the database.
How can i do that ?
Thanks in advance.

You can run an UPDATE query that updates a field relative to itself, as an example "UPDATE tbl SET tblfield = tblfield + 1" With no qualifiers, this will make every value for tblfield in that table 1 larger than it was before.

You don't say what database you're using, but you would want string concatenate functions. Assuming MySQL your query would be:

UPDATE news SET content = concat(content, '<br> Approved by Admin'

And that's it. Keep in mind that with no qualifiers (i.e. "WHERE category = 'approved'" or whatever) it will update *all* fields. If that's what you want, you're done.

This is my first post here. If I get formatting wrong I apologize.

Thanks for your response ,but i am using mysql ,as shown in the middle :
DaniWeb Community > Web Development > Databases > MySQL
And wellcome to the board =)

Thanks for your response ,but i am using mysql ,as shown in the middle :
DaniWeb Community > Web Development > Databases > MySQL
And wellcome to the board =)

The above queries are for MySQL. Did you try it?

Yes it worked.
And the last response was fully for adamsonsk.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.