Gynteniuxas
Gynteniuxas

Reputation: 7103

Cannot execute multiple MariaDB queries using PHP

I have faced a slight problem with executing SQL query in MariaDB. All PHP variables are not empty and I would like to execute two queries at the same time. In MySQL it is working but in MariaDB server I cannot as I get an error I have a query:

UPDATE users SET name = $receivedName, email = $receivedEmail WHERE id = $id1; UPDATE posts SET id = $userid WHERE id = $receivedID

The error I get:

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 'UPDATE posts SET id = 50 WHERE id = 56 /* /takechange.php */' at line 1

I know it is not a shiny idea to execute two queries which are assigned to single variable, but at the moment I can barely change any code. I guess this is not how to join multiple queries in MariaDB. Can you tell me how to edit this query?

Thanks in advance.

Upvotes: 2

Views: 4915

Answers (2)

Erwin
Erwin

Reputation: 21

This is the reason why i couldn't exploit more an SQLi vulnerability in my own code, so better to leave it as it is and execute two, as the guys said

Upvotes: 0

Drew
Drew

Reputation: 24960

You need to use mysqli Multi Query or execute your statements separately.

You have multiple statements being passed as you know.

PHP Manual page on Multi Query

Executes one or multiple queries which are concatenated by a semicolon.

Upvotes: 2

Related Questions