I have these sql statements in a php function and I have passed all the needed variables. I have 2 insert statements in the query. They are inserting data into the same table, the first insert is for main service, and the second one if for an add-on service in my website.
SQL somehow takes the value of $userid and $item_label and the first insert works just fine. The second insert won't work unless I changed $userid and $item_label into static values, like '123','122'. (so basically, if I leave them as :userid
, :item_label
, SQL won't insert the values into the table)
But other overlapping variables like $filename
, both insert statement used do not cause any of the problems.
And $userid
is not the targeted table's index or anything. So, please help. and here is the code
function add_writing_editing_to_table($userid, $item_label, $basic_writing_service_id, $basic_writing_price, $editing_service_subcategory, $editing_service_id, $editing_serivce_price, $filename, $new_filename){
global $db;
$query = "INSERT INTO op_cart
(service_category, userid, item_label, service_subcategory, service_id, is_addon, unit, total_price, filename, new_filename, checkout)
VALUES
('writing', :userid, :item_label, 'basic_writing', :basic_writing_service_id, '0', '1', :basic_writing_price, :filename, :new_filename, '0'),
('editing', :userid, :item_label, :editing_service_subcategory, :editing_service_id, '1', '1', :editing_serivce_price, :filename, :new_filename, '0');";
$statement = $db->prepare($query);
$statement->bindValue(':userid', $userid);
$statement->bindValue(':item_label', $item_label);
$statement->bindValue(':basic_writing_service_id', $basic_writing_service_id);
$statement->bindValue(':basic_writing_price', $basic_writing_price);
$statement->bindValue(':filename', $filename);
$statement->bindValue(':new_filename', $new_filename);
$statement->bindValue(':editing_service_subcategory', $editing_service_subcategory);
$statement->bindValue(':editing_service_id', $editing_service_id);
$statement->bindValue(':editing_serivce_price', $editing_serivce_price);
$statement->execute();
$statement->closeCursor();
}