ThisisForReal Posted May 23, 2010 Share Posted May 23, 2010 My friend and I are working on a website. He is doing all the database operations, and I'm coding the PHP. Neither of us are very well versed in this exciting world of coding and database design, but we're learning fast. He created a stored procedure for updating a table. When a user updates the form on our website, the stored procedure is called and the table is successfully updated in mysql. To verify (and thus redirect the user to the appropriate page), the stored procedure ends by selecting 1 if successful, else 0. We have tested this by running the stored procedure in mysql workbench (see attachment below). On my end, I'm having trouble using the 'select 1' that he is sending me. I've run gettype and echoed the variable, and it tells me that I'm working with an array, but it won't tell me whether it's a 1 (successfully updating table). It simply says you have an array, and when I do my if{ and ask whether the value of the array is a 1 (or if I merely ask to echo the value), I can't work with the result. We're trying to return a 1,0 result while keeping the load on our database to a minimum. We could modify the stored procedure to perform logic on its end and return a 1 or a 0 from a table, but that sounds like a foolish way of solving the problem. Does anyone know the sql terminology he needs to use to send me an array that I can work with. Or am I making the error? (For reference, my php code is below). $query = "CALL mealshare.spUpdateGroup('$mtgid','$description','','','','','$target')"; $data = mysqli_query($dbc,$query) or die('Could not execute the command'); $answer = mysqli_fetch_array($data); echo '<p> first is gettype answer<br />'; //my attempt at debugging (see picture attachment) echo gettype($answer); echo "$answer"; echo $answer; if ($answer == 0) {... Hope all that was clear as mud. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/202671-mysql-stored-procedure-selects-1-php-array-doesnt-see-the-1/ Share on other sites More sharing options...
jskywalker Posted May 24, 2010 Share Posted May 24, 2010 did you try: echo $answer[0]; Quote Link to comment https://forums.phpfreaks.com/topic/202671-mysql-stored-procedure-selects-1-php-array-doesnt-see-the-1/#findComment-1062668 Share on other sites More sharing options...
ThisisForReal Posted May 24, 2010 Author Share Posted May 24, 2010 genius... and while working on a concurrent issue (doing an array_push) I was just about to discover the answer. Thank you so much for your help! Quote Link to comment https://forums.phpfreaks.com/topic/202671-mysql-stored-procedure-selects-1-php-array-doesnt-see-the-1/#findComment-1062680 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.