I have a form that takes a CSV file and uploads it into a MySQL table. Each of the entries upon the upload features characters that I need to remove, as well as the head row. For example:
`| ="username" | ="URL" |`
`| ="john" | ="url" |`
`| ="mike" | ="url1" |`
At the moment, I use the following two queries via phpMyAdmin to update the entries and delete the first row:
update control set userName = REPLACE(REPLACE(REPLACE(userName,'"',''), '"',''), '=','');
DELETE FROM control WHERE userName = "Username"
Is there a way to combine the two queries into a single one with the goal of running the resulting query with a button click through PHP script?
2
Answers
You can run the two queries by combining them in to one variable like
You cannot combine a
DELETE
query with anUPDATE
query unfortunately.What you can do however is combine the queries inside a transaction so that they are run consecutively and are rolled back if anything goes wrong.
In terms of PHP this could look something like the following:
Above is using the PHP PDO library as an example.
MySQL Transaction Documentation
PHP PDO Transaction