Emma
Emma

Reputation: 21

How do I remove slashes during a select statement

Please I am new. I am performing an insert select and I want to remove the slashes in a particular field say field b at the select portion of the query. eg. insert into mytable(a,b,c) select a, stripslashes(b),c from mysecondtable;

Please help.

Upvotes: 2

Views: 7370

Answers (4)

Tom Bartel
Tom Bartel

Reputation: 2258

you can use REPLACE like this:

insert into mytable(a,b,c) 
select a, REPLACE(b, '\\', '\') as b, c 
  from mysecondtable;

The REPLACE expression might have to be refined, but I hope this gets you started.

Upvotes: 2

Sarfraz
Sarfraz

Reputation: 382881

use the SUBSTR function of mysql or do something like this:

"insert into table set value = " . stripslashes('whatever')

Upvotes: 0

miku
miku

Reputation: 188174

You can use MySQL String functions, e.g. replace.

Also consider sanitizing or preparing any input to the SELECT in the calling application before you execute the query.

Upvotes: 0

Ben
Ben

Reputation: 11208

Are you doint this with PHP? Then a simple $fieldB = strip_slashes($_POST['b']); should do. You should then use $fieldB in your query.

Upvotes: -1

Related Questions