MarioApprentice Posted July 3, 2013 Share Posted July 3, 2013 I have a code that has to save a more than one reservation into a database. This is the code $sql = 'INSERT INTO reservations(name, price, user_id, proizvod, num_items, taken, date) VALUES( (SELECT name FROM product WHERE id=:id), (SELECT price FROM product WHERE id=:id), :user_id, (SELECT id FROM product WHERE id=:id), :num_items, :taken, :date )'; $stmt->bindValue('user_id', 5, PDO::PARAM_INT); /* same for the rest of the binded values. */ But it says that the 'number of binded variables does not match number of tokes' which is not true. I have checked it 256789521 times in the past hour like some kind of crazy person. The manual doesn't say anything about partial binding of items to be inserted. Does anyone know what the problem is? Quote Link to comment https://forums.phpfreaks.com/topic/279829-bindvalue-with-insert-and-inner-select/ Share on other sites More sharing options...
DaveyK Posted July 3, 2013 Share Posted July 3, 2013 http://php.net/manual/en/pdostatement.bindvalue.php In the examples they also use the colons ':'. Try that. Quote Link to comment https://forums.phpfreaks.com/topic/279829-bindvalue-with-insert-and-inner-select/#findComment-1439260 Share on other sites More sharing options...
MarioApprentice Posted July 3, 2013 Author Share Posted July 3, 2013 yea, this is a configured example. i have the colons when the mistake happens, i just made a mistake when i wrote the post. the question still stands. sorry about that Quote Link to comment https://forums.phpfreaks.com/topic/279829-bindvalue-with-insert-and-inner-select/#findComment-1439265 Share on other sites More sharing options...
mac_gyver Posted July 3, 2013 Share Posted July 3, 2013 you need to post the actual code you want help with. otherwise how could someone possibly tell you what is wrong with it? Quote Link to comment https://forums.phpfreaks.com/topic/279829-bindvalue-with-insert-and-inner-select/#findComment-1439268 Share on other sites More sharing options...
MarioApprentice Posted July 3, 2013 Author Share Posted July 3, 2013 (edited) you need to post the actual code you want help with. otherwise how could someone possibly tell you what is wrong with it? well its the sam principle and its on croatian so i had to translate it to make it more readable for you, but if it help, here it is, the same code on english. If i didn't put a colon there somewhere, its a mistake in the post, not in the actual code. $sql = 'INSERT INTO reservations(name, price, user_id, product_id, number_of_items, taken, datum_postavljanja) VALUES( (SELECT name FROM product WHERE id=:id), (SELECT price FROM product WHERE id=:id), :user_id (SELECT id FROM product WHERE id=:id), :number_of_items, :taken, :date_of_request )'; $stmt->bindValue(':user_id', $_SESSION['user']->getField('id'), PDO::PARAM_INT); // this is an object containg data from logged in user $stmt->bindValue(':number_of_items', $komadi[$counter], PDO::PARAM_INT); // index counter for the number of items user whats to order $stmt->bindValue(':taken', 1, PDO::PARAM_INT); $stmt->bindValue(':date_of_request', date('Y-m-d'), PDO::PARAM_STR); $stmt->execute(); Edited July 3, 2013 by MarioApprentice Quote Link to comment https://forums.phpfreaks.com/topic/279829-bindvalue-with-insert-and-inner-select/#findComment-1439273 Share on other sites More sharing options...
mac_gyver Posted July 3, 2013 Share Posted July 3, 2013 you are not binding anything for the :id placeholder. you have 5 placeholders in the query and only 4 bind statements. Quote Link to comment https://forums.phpfreaks.com/topic/279829-bindvalue-with-insert-and-inner-select/#findComment-1439278 Share on other sites More sharing options...
MarioApprentice Posted July 3, 2013 Author Share Posted July 3, 2013 you are not binding anything for the :id placeholder. you have 5 placeholders in the query and only 4 bind statements. oh god, its an embarement. and this is the third time on this forum. sorry for the lost time. i shall go into the nearest corner and cry. Quote Link to comment https://forums.phpfreaks.com/topic/279829-bindvalue-with-insert-and-inner-select/#findComment-1439279 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.