SupaOden
SupaOden

Reputation: 742

mysql error but works fine on mysql workbench

MySQL Query works fine using MySQL workbench but produces an error when I am executing it through PHP.

$sql = "INSERT INTO authors (submission_id, first_name, last_name, email, affiliation, country)
VALUES ('83', 'Chris', 'Hobbit', '[email protected]','Maryland', 'PK');

UPDATE articles
SET title='83',
abstract = 'Comp'
where article_id = '83'; 
"; 

$result = Model::getConnection()->query($sql) or die(mysqli_error(Model::getConnection()));

This is the error I get from PHP.

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UPDATE articles SET title='83', abstract = 'Comp' where article_id = '8' at line 1

Yet this same SQL script works fine on MySQL workbench. Whats the problem?

Upvotes: 1

Views: 495

Answers (2)

SuperNoob
SuperNoob

Reputation: 392

Put your sql statement on two variables

 $query = "INSERT INTO authors (submission_id, first_name, last_name, email, affiliation, country)
 VALUES ('83', 'Chris', 'Hobbit', '[email protected]','Maryland', 'PK')";

 $query1 = "UPDATE articles SET title='83', abstract = 'Comp' where article_id = '83'"; 

Then execute your queries:

 $result = Model::getConnection()->query($query) or die(mysqli_error(Model::getConnection()));
 $result = Model::getConnection()->query($query1) or die(mysqli_error(Model::getConnection()));

Upvotes: 0

Matt Dodge
Matt Dodge

Reputation: 11142

You cannot execute multiple queries with mysql_query. Split your query into two (and get rid of the semicolons I think) and call mysql_query twice

Upvotes: 4

Related Questions