php - Creating Array for PDO Execute Statement -
I'm trying to dynamically create an array for the executable part of inserting the PDO. My working code includes this type of text:
$ stmt-> Execute (': fname' = & gt; $ _POST ['fname'], ': lname' = & gt; $ _POST ['lname'], ': email' = & gt; $ _POST ['email ']));
My first attempt to create an array:
$ insert_execute = array (); Foreign currency ($ column = & gt; $ value as $ value) {array_push ($ insert_execute, ":". $ Column. "= =" "." ". $ Value" "''))} < / Code>
But when I try to execute I get a PDO error:
SQLSTATE [HY093]: Invalid parameter number: parameter is not defined
And when I print the result, then there is an extra parameter:
array ([0] => fname = & gt; ; 'Test Name' [1] = & gt; lname = & gt; Final Test '[2] = & gt; Email = & gt; St@email.com ')
How do I remove array_push to remove [0], [1], [2] etc. in the array?
You are looking more and more complex to the case. You already have an associative array for the values of parameter names, so that you You can use that
$ stmt- & gt; executed ($ value);
The colon prefix ( :
) is optional. If it is not there, the PDO extension will automatically add it.
Comments
Post a Comment