Skip to content
Advertisement

How to insert array as key => value with string value into sql using php [closed]

I am having just a small problem with the name array, when i perform the above code every row’s member values takes the value of

What i am getting

What i want is this

Note: Every Other Column is perfectly inserted and I would take into account the SQL Injection security later on.

Advertisement

Answer

I think you just need to keep $name as an array, don’t implode it back into a string, and then loop over that. I have no idea what is in $give and others. I see that they are arrays but I don’t understand their relationship to $name. The below code does this and inserts 16 records (assuming 4 names):

If, however, there’s some magic relation between the session data and your other variables, and you really want to only insert 4 rows, then this version which still track $x can be used.

I know you said you’ll worry about escaping it later, but I just switched it over to a prepared statement any because it is much easier to ready for everyone.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement