funbinod Posted August 5, 2019 Share Posted August 5, 2019 hello all! i'm trying something for binding parameters to a prepared statement like below. $tbl = 'stock'; $cols = 'icode=?, item=?, catid=?, description=?, unitid=?, pprice=?, sprice=?, oqty=?, oprice=?, oamt=?, bcode=?'; // $vals = "'101', 'ASUS H61M-E', 'abcde', '2', '1', '5300.00', '6500.00', '11', '5300', '55528', '101'"; $vals = "101, ASUS H61M-E, abcde, 2, 1, 5300.00, 6500.00, 11, 5300, 55528, 101"; $uq = $mysqli->prepare("UPDATE $tbl SET $cols WHERE $whcol='$whval'"); if (!$uq) { $msg = "Error1: $mysqli->error!"; } else { $uq->bind_param('sssssssssss', $vals); // this doesn't work. // $uq->bind_param('sssssssssss', 101, ASUS H61M-E, abcde, 2, 1, 5300.00, 6500.00, 11, 5300, 55528, 101); // but this works well. if (!$uq->execute()) { $msg = "Error3: $uq->error!"; ///// this says "No data supplied for parameters in prepared statement." } else { $msg = "UPDATED successfully!"; } } here i'm trying to put all the update values into a string and then bind it to the statement. but this says "No data supplied for parameters in prepared statement". but when i use individual values, it works fine. please suggest me something. thanks in advance. Link to comment Share on other sites More sharing options...
Funce Posted August 5, 2019 Share Posted August 5, 2019 mysqli_stmt::bind_param binds each variable to a matching parameter. You cannot match all of them to one. It doesn't work like that. (Neither can you attempt to use a string like an array) What you can do however, is bind an array using variable length argument lists. Use ... to indicate an argument list as below. <?php $vals = [101, "ASUS H61M-E", "abcde", 2, 1, 5300.00, 6500.00, 11, 5300, 55528, 101]; $uq = $mysqli->prepare("UPDATE $tbl SET $cols WHERE $whcol='$whval'"); if (!$uq) { $msg = "Error1: $mysqli->error!"; } else { $uq->bind_param('issiiddiiii', ...$vals); 1 Link to comment Share on other sites More sharing options...
funbinod Posted August 6, 2019 Author Share Posted August 6, 2019 thank u for the replay. it worked. its great suggestion. thank u again. 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