jimfog Posted May 5, 2015 Share Posted May 5, 2015 I am trying to create a prepare statement where multiple rows will be updated(7). I am using a foreach loop to do that where I am accessing the contents of an array(these contents are to be inserted to the DB). here is the loop: foreach ($times as $day => $hours) { $stmt->bind_param('ssis',$hours['open'],$hours['close'] ,$id,$day); $stmt->execute(); } here is the output of $times...it is a multidimensional array: array(8) { ["sunday"]=> array(2) { ["open"]=> NULL ["close"]=> NULL } ["monday"]=> array(2) { ["open"]=> NULL ["close"]=> NULL } ["tuesday"]=> array(2) { ["open"]=> NULL ["close"]=> NULL } ["wednesday"]=> array(2) { ["open"]=> NULL ["close"]=> NULL } ["thursday"]=> array(2) { ["open"]=> string(5) "11:00" ["close"]=> string(5) "17:00" } ["friday"]=> array(2) { ["open"]=> NULL ["close"]=> NULL } ["saturday"]=> array(2) { ["open"]=> NULL ["close"]=> NULL } the above is to show we are dealing with an array indeed. And here is my problem: I get this message: Cannot use a scalar value as an array in the bind_param statement regarding $hours['open'],$hours['close']... it does not make any sense...what do you think? Link to comment Share on other sites More sharing options...
justsomeguy Posted May 5, 2015 Share Posted May 5, 2015 array(8) {The array has 8 elements, you only show 7. Where's the other one? I bet it's not an array. Link to comment Share on other sites More sharing options...
jimfog Posted May 5, 2015 Author Share Posted May 5, 2015 here is the var_dump...again...you were I right I had not included a member(my mistake)...and probably this is causing the problem...but I am not sure...I want your opinion too. If this 8th member is causing the issue....I would like to here some explanation: array(8) { ["sunday"]=> array(2) { ["open"]=> NULL ["close"]=> NULL } ["monday"]=> array(2) { ["open"]=> NULL ["close"]=> NULL } ["tuesday"]=> array(2) { ["open"]=> NULL ["close"]=> NULL } ["wednesday"]=> array(2) { ["open"]=> NULL ["close"]=> NULL } ["thursday"]=> array(2) { ["open"]=> string(5) "10:30" ["close"]=> string(5) "16:30" } ["friday"]=> array(2) { ["open"]=> NULL ["close"]=> NULL } ["saturday"]=> array(2) { ["open"]=> NULL ["close"]=> NULL } ["id"]=> int(8)} Link to comment Share on other sites More sharing options...
Ingolme Posted May 5, 2015 Share Posted May 5, 2015 "id" is an integer, which is not an array. You can't access a property ['open'] or ['close'] in it. Link to comment Share on other sites More sharing options...
jimfog Posted May 6, 2015 Author Share Posted May 6, 2015 "id" is an integer, which is not an array. You can't access a property ['open'] or ['close'] in it. yes..that is the cause of the problem..thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now