Re: [PHP-DB] Re: Problems w/ insert -- SOLVED!!!
On 9/13/2012 9:15 PM, Ethan Rosenberg, PhD wrote: Dear list - Thanks to all. It now works! The problem, as you correctly noted, was the erroneous inclusion of the bind-results statement. Removed that and it worked!! Thanks again! Ethan Methinks Ethan is thanking the group for assistance on his PREVIOUS problem with the prepared INSERT query. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Problems w/ insert -- SOLVED!!!
Dear list - Thanks to all. It now works! The problem, as you correctly noted, was the erroneous inclusion of the bind-results statement. Removed that and it worked!! Thanks again! Ethan -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Problems w/ insert
On 9/11/2012 12:04 AM, Matt Pelmear wrote: Ethan, I am curious why you are using mysqli_stmt_bind_result() on a statement that is an INSERT query? I don't use mysqli, but as I read the documentation it seems to me that this method is intended to bind results from a SELECT query into variables so that you can simply call mysqli_stmt_fetch() in a loop and have the variables magically contain the data from the next row. Perhaps mysqli is confused because you are both mapping data to be bound (with mysqli_stmt_bind_param()) and to be returned (with mysqli_stmt_bind_result()) on the same INSERT query? If you are just trying to insert, you should only need mysqli_stmt_bind_param() (which, by my count, has one parameter too many right now in your code) and mysqli_stmt_execute() (and probably not mysql_stmt_bind_param() and mysql_stmt_fetch()). See "Example #2" here: http://us.php.net/manual/en/mysqli-stmt.execute.php -Matt On 09/10/2012 08:29 PM, Karl DeSaulniers wrote: On Sep 10, 2012, at 7:06 PM, Ethan Rosenberg, PhD wrote: Dear list - Here is my code: $sql3 = "select max(Indx) from Visit3"; $result7 = mysqli_query($cxn, $sql3); $row7 = mysqli_fetch_array($result7, MYSQLI_BOTH); $Indx = $row7[0]; $sql2 = "INSERT INTO Visit3(Indx, Site, MedRec, Notes, Weight, BMI, Date) VALUES(?, ?, ?, ?, ?, ?, ? )"; mysqli_stmt_prepare( $stmt, $sql2 ); $_POST['Indx'] = $Indx; $_POST['Date'] = $Date; mysqli_stmt_bind_param($stmt, 'isisiis', $_POST['Indx'], $_POST['Site'], $_POST['MedRec'], $_POST['Notes'], $_POST['Weight'], $_POST['BMI'], $_POST['Date']); mysqli_execute($stmt); mysqli_stmt_bind_result($stmt, $_POST['Indx'], $_POST['Site'], $_POST['MedRec'], $_POST['Notes'], $_POST['Weight'], $_POST['BMI'], $_POST['Date']); *//The error is in this statement* mysqli_stmt_fetch($stmt); mysqli_stmt_close($stmt); *Warning: mysqli_stmt_bind_result(): Number of bind variables doesn't match number of fields in prepared statement* * * Help and advice, please. Ethan Rosenberg -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Maybe right here there needs to be something? mysqli_stmt_bind_result($stmt, ?, $_POST['Indx'], ... in the statement above you have. mysqli_stmt_bind_param($stmt, 'isisiis', $_POST['Indx'], ... what ever 'isisiis' is, you need to put somehting in your ...bind_result() I think. maybe.. mysqli_stmt_bind_result($stmt, '', $_POST['Indx'], or mysqli_stmt_bind_result($stmt, 'isisiis', $_POST['Indx'], sorry for not a more concrete answer. I am guessing a little. :) HTH, Karl DeSaulniers Design Drumm http://designdrumm.com If I had read further I would not have made my post a moment ago. Give Matt here the credit for seeing the forest thru the trees. :) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Problems w/ insert
On 9/10/2012 8:06 PM, Ethan Rosenberg, PhD wrote: Dear list - Here is my code: $sql3 = "select max(Indx) from Visit3"; $result7 = mysqli_query($cxn, $sql3); $row7 = mysqli_fetch_array($result7, MYSQLI_BOTH); $Indx = $row7[0]; $sql2 = "INSERT INTO Visit3(Indx, Site, MedRec, Notes, Weight, BMI, Date) VALUES(?, ?, ?, ?, ?, ?, ? )"; mysqli_stmt_prepare( $stmt, $sql2 ); $_POST['Indx'] = $Indx; $_POST['Date'] = $Date; mysqli_stmt_bind_param($stmt, 'isisiis', $_POST['Indx'], $_POST['Site'], $_POST['MedRec'], $_POST['Notes'], $_POST['Weight'], $_POST['BMI'], $_POST['Date']); mysqli_execute($stmt); mysqli_stmt_bind_result($stmt, $_POST['Indx'], $_POST['Site'], $_POST['MedRec'], $_POST['Notes'], $_POST['Weight'], $_POST['BMI'], $_POST['Date']); *//The error is in this statement* mysqli_stmt_fetch($stmt); mysqli_stmt_close($stmt); *Warning: mysqli_stmt_bind_result(): Number of bind variables doesn't match number of fields in prepared statement* * * Help and advice, please. Ethan Rosenberg Ethan - PS to my other response: I think you should make a change to use the preferred syntax for the execute statement. The one you are using is deprecated, so will be removed in the future. May as well write code that isn't already on the way out. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Problems w/ insert
On 9/10/2012 8:29 PM, Karl DeSaulniers wrote: On Sep 10, 2012, at 7:06 PM, Ethan Rosenberg, PhD wrote: Dear list - Here is my code: $sql3 = "select max(Indx) from Visit3"; $result7 = mysqli_query($cxn, $sql3); $row7 = mysqli_fetch_array($result7, MYSQLI_BOTH); $Indx = $row7[0]; $sql2 = "INSERT INTO Visit3(Indx, Site, MedRec, Notes, Weight, BMI, Date) VALUES(?, ?, ?, ?, ?, ?, ? )"; mysqli_stmt_prepare( $stmt, $sql2 ); $_POST['Indx'] = $Indx; $_POST['Date'] = $Date; mysqli_stmt_bind_param($stmt, 'isisiis', $_POST['Indx'], $_POST['Site'], $_POST['MedRec'], $_POST['Notes'], $_POST['Weight'], $_POST['BMI'], $_POST['Date']); mysqli_execute($stmt); mysqli_stmt_bind_result($stmt, $_POST['Indx'], $_POST['Site'], $_POST['MedRec'], $_POST['Notes'], $_POST['Weight'], $_POST['BMI'], $_POST['Date']); *//The error is in this statement* mysqli_stmt_fetch($stmt); mysqli_stmt_close($stmt); *Warning: mysqli_stmt_bind_result(): Number of bind variables doesn't match number of fields in prepared statement* * * Help and advice, please. Ethan Rosenberg -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Maybe right here there needs to be something? mysqli_stmt_bind_result($stmt, ?, $_POST['Indx'], ... in the statement above you have. mysqli_stmt_bind_param($stmt, 'isisiis', $_POST['Indx'], ... what ever 'isisiis' is, you need to put somehting in your ...bind_result() I think. maybe.. mysqli_stmt_bind_result($stmt, '', $_POST['Indx'], or mysqli_stmt_bind_result($stmt, 'isisiis', $_POST['Indx'], sorry for not a more concrete answer. I am guessing a little. :) HTH, Karl DeSaulniers Design Drumm http://designdrumm.com Ethan, This is almost the exact same problem you posted last week and we were unable to solve it then. Having said that I think I suddenly see it. An "INSERT" query does not return any 'result', as I believe the intent of the 'bind-result' call is designed for. If you were doing a SELECT to pull those fields from the table this would work I'm guessing. But since it is an INSERT, there are no fields to be bound. That is the error! -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Problems w/ insert
Ethan, I am curious why you are using mysqli_stmt_bind_result() on a statement that is an INSERT query? I don't use mysqli, but as I read the documentation it seems to me that this method is intended to bind results from a SELECT query into variables so that you can simply call mysqli_stmt_fetch() in a loop and have the variables magically contain the data from the next row. Perhaps mysqli is confused because you are both mapping data to be bound (with mysqli_stmt_bind_param()) and to be returned (with mysqli_stmt_bind_result()) on the same INSERT query? If you are just trying to insert, you should only need mysqli_stmt_bind_param() (which, by my count, has one parameter too many right now in your code) and mysqli_stmt_execute() (and probably not mysql_stmt_bind_param() and mysql_stmt_fetch()). See "Example #2" here: http://us.php.net/manual/en/mysqli-stmt.execute.php -Matt On 09/10/2012 08:29 PM, Karl DeSaulniers wrote: On Sep 10, 2012, at 7:06 PM, Ethan Rosenberg, PhD wrote: Dear list - Here is my code: $sql3 = "select max(Indx) from Visit3"; $result7 = mysqli_query($cxn, $sql3); $row7 = mysqli_fetch_array($result7, MYSQLI_BOTH); $Indx = $row7[0]; $sql2 = "INSERT INTO Visit3(Indx, Site, MedRec, Notes, Weight, BMI, Date) VALUES(?, ?, ?, ?, ?, ?, ? )"; mysqli_stmt_prepare( $stmt, $sql2 ); $_POST['Indx'] = $Indx; $_POST['Date'] = $Date; mysqli_stmt_bind_param($stmt, 'isisiis', $_POST['Indx'], $_POST['Site'], $_POST['MedRec'], $_POST['Notes'], $_POST['Weight'], $_POST['BMI'], $_POST['Date']); mysqli_execute($stmt); mysqli_stmt_bind_result($stmt, $_POST['Indx'], $_POST['Site'], $_POST['MedRec'], $_POST['Notes'], $_POST['Weight'], $_POST['BMI'], $_POST['Date']); *//The error is in this statement* mysqli_stmt_fetch($stmt); mysqli_stmt_close($stmt); *Warning: mysqli_stmt_bind_result(): Number of bind variables doesn't match number of fields in prepared statement* * * Help and advice, please. Ethan Rosenberg -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Maybe right here there needs to be something? mysqli_stmt_bind_result($stmt, ?, $_POST['Indx'], ... in the statement above you have. mysqli_stmt_bind_param($stmt, 'isisiis', $_POST['Indx'], ... what ever 'isisiis' is, you need to put somehting in your ...bind_result() I think. maybe.. mysqli_stmt_bind_result($stmt, '', $_POST['Indx'], or mysqli_stmt_bind_result($stmt, 'isisiis', $_POST['Indx'], sorry for not a more concrete answer. I am guessing a little. :) HTH, Karl DeSaulniers Design Drumm http://designdrumm.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Problems w/ insert
On Sep 10, 2012, at 7:06 PM, Ethan Rosenberg, PhD wrote: Dear list - Here is my code: $sql3 = "select max(Indx) from Visit3"; $result7 = mysqli_query($cxn, $sql3); $row7 = mysqli_fetch_array($result7, MYSQLI_BOTH); $Indx = $row7[0]; $sql2 = "INSERT INTO Visit3(Indx, Site, MedRec, Notes, Weight, BMI, Date) VALUES(?, ?, ?, ?, ?, ?, ? )"; mysqli_stmt_prepare( $stmt, $sql2 ); $_POST['Indx'] = $Indx; $_POST['Date'] = $Date; mysqli_stmt_bind_param($stmt, 'isisiis', $_POST['Indx'], $_POST['Site'], $_POST['MedRec'], $_POST['Notes'], $_POST['Weight'], $_POST['BMI'], $_POST['Date']); mysqli_execute($stmt); mysqli_stmt_bind_result($stmt, $_POST['Indx'], $_POST['Site'], $_POST['MedRec'], $_POST['Notes'], $_POST['Weight'], $_POST['BMI'], $_POST['Date']); *// The error is in this statement* mysqli_stmt_fetch($stmt); mysqli_stmt_close($stmt); *Warning: mysqli_stmt_bind_result(): Number of bind variables doesn't match number of fields in prepared statement* * * Help and advice, please. Ethan Rosenberg -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Maybe right here there needs to be something? mysqli_stmt_bind_result($stmt, ?, $_POST['Indx'], ... in the statement above you have. mysqli_stmt_bind_param($stmt, 'isisiis', $_POST['Indx'], ... what ever 'isisiis' is, you need to put somehting in your ...bind_result() I think. maybe.. mysqli_stmt_bind_result($stmt, '', $_POST['Indx'], or mysqli_stmt_bind_result($stmt, 'isisiis', $_POST['Indx'], sorry for not a more concrete answer. I am guessing a little. :) HTH, Karl DeSaulniers Design Drumm http://designdrumm.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Problems w/ insert
Dear list - Here is my code: $sql3 = "select max(Indx) from Visit3"; $result7 = mysqli_query($cxn, $sql3); $row7 = mysqli_fetch_array($result7, MYSQLI_BOTH); $Indx = $row7[0]; $sql2 = "INSERT INTO Visit3(Indx, Site, MedRec, Notes, Weight, BMI, Date) VALUES(?, ?, ?, ?, ?, ?, ? )"; mysqli_stmt_prepare( $stmt, $sql2 ); $_POST['Indx'] = $Indx; $_POST['Date'] = $Date; mysqli_stmt_bind_param($stmt, 'isisiis', $_POST['Indx'], $_POST['Site'], $_POST['MedRec'], $_POST['Notes'], $_POST['Weight'], $_POST['BMI'], $_POST['Date']); mysqli_execute($stmt); mysqli_stmt_bind_result($stmt, $_POST['Indx'], $_POST['Site'], $_POST['MedRec'], $_POST['Notes'], $_POST['Weight'], $_POST['BMI'], $_POST['Date']); *//The error is in this statement* mysqli_stmt_fetch($stmt); mysqli_stmt_close($stmt); *Warning: mysqli_stmt_bind_result(): Number of bind variables doesn't match number of fields in prepared statement* * * Help and advice, please. Ethan Rosenberg -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php