Luis Liz
Luis Liz

Reputation: 1959

Semicolon separated queries in a single string failing to execute in CodeIgniter query() call

I have tried to fix the query but it still doesn't work

This is the error:

Error Number: 1064

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 'INSERT INTO user_notifications (id, usr_id, notification_message, sender`,' at line 3

DELETE FROM account_requests WHERE usrs_id = '' AND account_requesting = '2'; INSERT INTO user_notifications (id, usr_id, notification_message, sender, show, date) VALUES (NULL, '', 'Successful account upgrade. You are now a Tutor', 'Codeg Account Wizard', 1, CURDATE()); INSERT INTO usrs_acc_type (usrs_usr_id, account_type_type_id) VALUES (, 2); UPDATE transactionSETorder_status= 'Completed' WHEREusr_id= ANDpurchase_type= 'Account Upgrade' ANDorder_status= 'Pending' ANDitem` = 'Tutor Account';

Filename: C:\Users\Supremekhaoz\Downloads\Dropbox\htdocs\codeg\system\database\DB_driver.php

Line Number: 330

The query:

DELETE FROM account_requests WHERE `usrs_id` = '$usr_id' AND `account_requesting` = '$type_id'; 
            
INSERT INTO user_notifications (`id, `usr_id`, `notification_message`, `sender`, show, `date`) VALUES (NULL, '$usr_id', 'Successful account upgrade. You are now a $type', 'Codeg Account Wizard', 1, CURDATE()); 

INSERT INTO usrs_acc_type (`usrs_usr_id`, `account_type_type_id`) VALUES ($usr_id, $type_id);

UPDATE `transaction` SET `order_status` = 'Completed' WHERE `usr_id` = $usr_id AND `purchase_type` = 'Account Upgrade' AND `order_status` = 'Pending' AND `item` = '$type Account';

Upvotes: 0

Views: 333

Answers (2)

Dwith
Dwith

Reputation: 3

$this->db->where('usrs_id',$usr_id);
$this->db->where('account_requesting',$type_id);
$this->db->delete('account_requests ');

You can use this code for deleting

Upvotes: 0

Kanishka Panamaldeniya
Kanishka Panamaldeniya

Reputation: 17566

if you are using codeigniter why are you not trying active records

$data = array(
   'id' => NULL ,
   'usr_id' => $usr_id ,
   'notification_message' => 'Successful account upgrade. You are now a '.$type,
   'sender' => 'Codeg Account Wizard',
   'show' => 1,
   'date' => time()
);

$this->db->insert('user_notifications', $data); 

and also check your $usr_id has a value , i think it has no value

Upvotes: 2

Related Questions