Hello so I have a table named tables that contains 9 fields (`id, first, second, third, fourth, fifth, sixth, seventh, eight) and if all of those fields aren't empty, I want to insert it as new records on the same table. This is my code for now:
$db = new db();
$bind = array(
":tid" => "1"
);
$results = $db->select("tables", "tableID = :tid", $bind);
foreach ($results as $r) {
$tableID = $r['id'];
$l1_1 = $r['first'];
$l1_2 = $r['second'];
$l1_3 = $r['third'];
$l1_4 = $r['fourth'];
$l1_5 = $r['fifth'];
$l1_6 = $r['sixth'];
$l1_7 = $r['seventh'];
$l1_8 = $r['eight'];
}
if($l1_1 != "" AND $l1_2 != "" AND $l1_3 != "" AND $l1_4 != "" AND $l1_5 != "" AND $l1_6 != "" AND $l1_7 != "" AND $l1_8 != "")
{
$db->insert("tables", array(
"first" => $l1_1,
"second" => $l1_2,
"third" => $l1_3,
"fourth" => $l1_4,
));
//insert 2nd record
$db->insert("tables", array(
"first" => $l1_5,
"second" => $l1_6,
"third" => $l1_7,
"fourth" => $l1_8,
));
}
I also have a long code that the summary of what it does is to check if field is empty and insert that data there, until all fields are filled. When the last data is entered, the code above will execute. When the last data is entered, it will do the code above that will check if all fields is empty and insert a new data. This code works but the last data being inserted appears blank in the new record being inserted.
I know my explanation is vague, but please just ask me what you want to know.