I need to insert something in my data-base but i need to loop through two tables to do something like this
<?php
include("../db_config.php"); //it contains the data-base informations
include("../refCode.php"); //it contains a functiont which gives a randomString
$refCode = RandomString(20);
if(!empty($_POST)){
$qid = 8;
$SQL = "INSERT INTO `saisie` (`sid`, `reference`) VALUES (NULL,?)";
$set = $db->prepare($SQL);
$result = $set->execute(array($refCode));
$sid = $db->lastInsertId();
$SQL = "SELECT cid FROM champs WHERE qid = ? ORDER BY ordre";
$set = $db->prepare($SQL);
$cids = $set->execute(array($qid));
$SQL = "INSERT INTO `donnees` (`sid`, `cid`, `valeur`) VALUES (?,?,?)";
$set = $db->prepare($SQL);
foreach ($_POST as $key => $value and $cids as $id => $cid) { //this is the line 24
$result = $set->execute(array($sid,$cid,$value));
}
}
?>
but this doesn't work, i get this error
Parse error: syntax error, unexpected 'and' (T_LOGICAL_AND), expecting :: (T_PAAMAYIM_NEKUDOTAYIM) in C:\wamp64\www\website\user\sumbit_answers.php on line 24