So, I have an array which I am combining to create an INSERT
command. (No sanitizing done yet, just a proof of concept).
$namedata
is the data for the "Name" field (for example "This Name")
$refdata
is the data for the "Ref" field (for example "43857368")
$CatRefData
is my array (for example, '23', '45', '2', '144')
I am formulating it as follows:
$inputdata = "'), ('".$namedata."', '".$refdata."', '";
$data = implode($inputdata, $CatRefData);
$result = "INSERT INTO `MyTable`('Name', 'Ref', 'Cat_Ref') VALUES ('".$data."')";
But the output comes out with the first instance of the array missing any of the additional "non-array" data, like this:
$result = INSERT INTO
MyTable
('Name', 'Ref', 'Cat_Ref') VALUES ('23'), ('This Name', '43857368', '45'), ('This Name', '43857368', '2'), ('This Name', '43857368', '144')
Can you see - the first instance, where the array value is '23', doesn't have any of the surrounding information.
What am I doing wrong?