In php, Moving a new row to another table and deleting old row

Hi, I already succeed moving a new row to another table if the field from new row doesn't have the first word that I categorized (like: IRC blablabla, PTM blablabla, ADM blablabla, BS blablabla).

But it can't delete the old row. Please help me with the script.

my php script:

INSERT INTO inbox_spam SELECT * FROM inbox 
WHERE TextDecoded NOT regexp ( select concat_ws ( '', '^(', group_concat(sms_keyword separator '|'), ').*' ) from sms_key)
select * from sms_key;
+-------------+
| sms_keyword |
+-------------+
| IRC         |
| PTM         |
| ADM         |
| BS          |
+-------------+
select * from inbox;
+------+----------------+
| x    | textdecoded    |
+------+----------------+
|    1 | IRC test1      |
|    2 | Hello, World!  |
|    3 | PTM test1      |
|    4 | Test ADM test1 |
+------+----------------+
select * from inbox_spam;
+------+----------------+
| x    | textdecoded    |
+------+----------------+
|    2 | Hello, World!  |
|    4 | Test ADM test1 |
+------+----------------+

Thank you :slight_smile:

That does not look like PHP. What database is this?

Hi, im using mysql. the script are trigered with bash script:

mysql -uroot -p123456 smsd -e "INSERT INTO inbox_spam 
SELECT * FROM inbox WHERE TextDecoded 
NOT regexp ( select concat_ws ( '', '^(', group_concat(sms_keyword separator '|'), ').*' ) from sms_key)"