I have made two functions to insert and update data to a database from a rather large form. My code below works fine, but I was wondering whether it was possible to make it much simpler through iteration or similar?
Here's my functions
which are called with
Here's my functions
Code:
function insertCF($id,$cf1_score,$cf1_isseen,$sc1_cf_id,$cf1_pdp,$cf1_redflag,$cf2_score,$cf2_isseen,$sc2_cf_id,$cf2pdp,$cf2_redflag,$cf3_score,$cf3_isseen,$sc3_cf_id,$cf3_pdp,$cf3_redflag,$cf4_score,$cf4_isseen,$sc4_cf_id,$cf4_pdp,$cf4_redflag,$cf5_score,$cf5_isseen,$sc5_cf_id,$cf5_pdp,$cf5_redflag,$cf6_score,$cf6_isseen,$sc6_cf_id,$cf6_pdp,$cf6_redflag,$cf7_score,$cf7_isseen,$sc7_cf_id,$cf7_pdp,$cf7_redflag,$cf8_score,$cf8_isseen,$sc8_cf_id,$cf8_pdp,$cf8_redflag,$cf9_score,$cf9_isseen,$sc9_cf_id,$cf9_pdp,$cf9_redflag,$cf10_score,$cf10_isseen,$sc10_cf_id,$cf10_pdp,$cf10_redflag,$cf11_score,$cf11_isseen,$sc11_cf_id,$cf11_pdp,$cf11_redflag,$cf12_score,$cf12_isseen,$sc12_cf_id,$cf12pdp,$cf12_redflag,$cf13_score,$cf13_isseen,$sc13_cf_id,$cf13_pdp,$cf13_redflag,$cf14_score,$cf14_isseen,$sc14_cf_id,$cf14_pdp,$cf14_redflag,$cf15_score,$cf15_isseen,$sc15_cf_id,$cf15_pdp,$cf15_redflag,$cf16_score,$cf16_isseen,$sc16_cf_id,$cf16_pdp,$cf16_redflag,$cf17_score,$cf17_isseen,$sc17_cf_id,$cf17_pdp,$cf17_redflag,$cf18_score,$cf18_isseen,$sc18_cf_id,$cf18_pdp,$cf18_redflag,$cf19_score,$cf19_isseen,$sc19_cf_id,$cf19_pdp,$cf19_redflag,$cf20_score,$cf20_isseen,$sc20_cf_id,$cf20_pdp,$cf20_redflag,$cfcomments,$redflagnotify)
{
$result = $this->Query("insert into mytable values ('','$cf1_score','$cf1_isseen','$sc1_cf_id','$cf1_pdp','$cf1_redflag','$cf2_score','$cf2_isseen','$sc2_cf_id','$cf2_pdp','$cf2_redflag','$cf3_score','$cf3_isseen','$sc3_cf_id','$cf3_pdp','$cf3_redflag','$cf4_score','$cf4_isseen','$sc4_cf_id','$cf4_pdp','$cf4_redflag','$cf5_score','$cf5_isseen','$sc5_cf_id','$cf5_pdp','$cf5_redflag','$cf6_score','$cf6_isseen','$sc6_cf_id','$cf6_pdp','$cf6_redflag','$cf7_score','$cf7_isseen','$sc7_cf_id','$cf7_pdp','$cf7_redflag','$cf8_score','$cf8_isseen','$sc8_cf_id','$cf8_pdp','$cf8_redflag','$cf9_score','$cf9_isseen','$sc9_cf_id','$cf9_pdp','$cf9_redflag','$cf10_score','$cf10_isseen','$sc10_cf_id','$cf10_pdp','$cf10_redflag','$cf11_score','$cf11_isseen','$sc11_cf_id','$cf11_pdp','$cf11_redflag','$cf12_score','$cf12_isseen','$sc12_cf_id','$cf12_pdp','$cf12_redflag','$cf13_score','$cf13_isseen','$sc13_cf_id','$cf13_pdp','$cf13_redflag','$cf14_score','$cf14_isseen','$sc14_cf_id','$cf14_pdp','$cf14_redflag','$cf15_score','$cf15_isseen','$sc15_cf_id','$cf15_pdp','$cf15_redflag','$cf16_score','$cf16_isseen','$sc16_cf_id','$cf16_pdp','$cf16_redflag','$cf17_score','$cf17_isseen','$sc17_cf_id','$cf17_pdp','$cf17_redflag','$cf18_score','$cf18_isseen','$sc18_cf_id','$cf18_pdp','$cf18_redflag','$cf19_score','$cf19_isseen','$sc19_cf_id','$cf19_pdp','$cf19_redflag','$cf20_score','$cf20_isseen','$sc20_cf_id','$cf20_pdp','$cf20_redflag','$cfcomments','$redflagnotify')");
}
function updateCF($cf1_score,$cf1_isseen,$sc1_cf_id,$cf1_pdp,$cf1_redflag,$cf2_score,$cf2_isseen,$sc2_cf_id,$cf2_pdp,$cf2_redflag,$cf3_score,$cf3_isseen,$sc3_cf_id,$cf3_pdp,$cf3_redflag,$cf4_score,$cf4_isseen,$sc4_cf_id,$cf4_pdp,$cf4_redflag,$cf5_score,$cf5_isseen,$sc5_cf_id,$cf5_pdp,$cf5_redflag,$cf6_score,$cf6_isseen,$sc6_cf_id,$cf6_pdp,$cf6_redflag,$cf7_score,$cf7_isseen,$sc7_cf_id,$cf7_pdp,$cf7_redflag,$cf8_score,$cf8_isseen,$sc8_cf_id,$cf8_pdp,$cf8_redflag,$cf9_score,$cf9_isseen,$sc9_cf_id,$cf9_pdp,$cf9_redflag,$cf10_score,$cf10_isseen,$sc10_cf_id,$cf10_pdp,$cf10_redflag,$cf11_score,$cf11_isseen,$sc11_cf_id,$cf11_pdp,$cf11_redflag,$cf12_score,$cf12_isseen,$sc12_cf_id,$cf12_pdp,$cf12_redflag,$cf13_score,$cf13_isseen,$sc13_cf_id,$cf13_pdp,$cf13_redflag,$cf14_score,$cf14_isseen,$sc14_cf_id,$cf14_pdp,$cf14_redflag,$cf15_score,$cf15_isseen,$sc15_cf_id,$cf15_pdp,$cf15_redflag,$cf16_score,$cf16_isseen,$sc16_cf_id,$cf16_pdp,$cf16_redflag,$cf17_score,$cf17_isseen,$sc17_cf_id,$cf17_pdp,$cf17_redflag,$cf18_score,$cf18_isseen,$sc18_cf_id,$cf18_pdp,$cf18_redflag,$cf19_score,$cf19_isseen,$sc19_cf_id,$cf19_pdp,$cf19_redflag,$cf20_score,$cf20_isseen,$sc20_cf_id,$cf20_pdp,$cf20_redflag,$cfcomments,$redflagnotify,$id,)
{
$result = $this->Query("update mytable set
cf1_score='$cf1_score',
cf1_isseen='$cf1_isseen',
sc1_cf_id='$sc1_cf_id',
cf1_pdp='$cf1_pdp',
cf1_redflag='$cf1_redflag',
cf2_score='$cf2_score',
cf2_isseen='$cf2_isseen',
sc2_cf_id='$sc2_cf_id',
cf2_pdp='$cf2_pdp',
cf2_redflag='$cf2_redflag',
cf3_score='$cf3_score',
cf3_isseen='$cf3_isseen',
sc3_cf_id='$sc3_cf_id',
cf3_pdp='$cf3_pdp',
cf3_redflag='$cf3_redflag',
cf4_score='$cf4_score',
cf4_isseen='$cf4_isseen',
sc4_cf_id='$sc4_cf_id',
cf4_pdp='$cf4_pdp',
cf4_redflag='$cf4_redflag',
cf5_score='$cf5_score',
cf5_isseen='$cf5_isseen',
sc5_cf_id='$sc5_cf_id',
cf5_pdp='$cf5_pdp',
cf5_redflag='$cf5_redflag',
cf6_score='$cf6_score',
cf6_isseen='$cf6_isseen',
sc6_cf_id='$sc6_cf_id',
cf6_pdp='$cf6_pdp',
cf6_redflag='$cf6_redflag',
cf7_score='$cf7_score',
cf7_isseen='$cf7_isseen',
sc7_cf_id='$sc7_cf_id',
cf7_pdp='$cf7_pdp',
cf7_redflag='$cf7_redflag',
cf8_score='$cf8_score',
cf8_isseen='$cf8_isseen',
sc8_cf_id='$sc8_cf_id',
cf8_pdp='$cf8_pdp',
cf8_redflag='$cf8_redflag',
cf9_score='$cf9_score',
cf9_isseen='$cf9_isseen',
sc9_cf_id='$sc9_cf_id',
cf9_pdp='$cf9_pdp',
cf9_redflag='$cf9_redflag',
cf10_score='$cf10_score',
cf10_isseen='$cf10_isseen',
sc10_cf_id='$sc10_cf_id',
cf10_pdp='$cf10_pdp',
cf10_redflag='$cf10_redflag',
cf11_score='$cf11_score',
cf11_isseen='$cf11_isseen',
sc11_cf_id='$sc11_cf_id',
cf11_pdp='$cf11_pdp',
cf11_redflag='$cf11_redflag',
cf12_score='$cf12_score',
cf12_isseen='$cf12_isseen',
sc12_cf_id='$sc12_cf_id',
cf12_pdp='$cf12_pdp',
cf12_redflag='$cf12_redflag',
cf13_score='$cf13_score',
cf13_isseen='$cf13_isseen',
sc13_cf_id='$sc13_cf_id',
cf13_pdp='$cf13_pdp',
cf13_redflag='$cf13_redflag',
cf14_score='$cf14_score',
cf14_isseen='$cf14_isseen',
sc14_cf_id='$sc14_cf_id',
cf14_pdp='$cf14_pdp',
cf14_redflag='$cf14_redflag',
cf15_score='$cf15_score',
cf15_isseen='$cf15_isseen',
sc15_cf_id='$sc15_cf_id',
cf15_pdp='$cf15_pdp',
cf15_redflag='$cf15_redflag',
cf16_score='$cf16_score',
cf16_isseen='$cf16_isseen',
sc16_cf_id='$sc16_cf_id',
cf16_pdp='$cf16_pdp',
cf16_redflag='$cf16_redflag',
cf17_score='$cf17_score',
cf17_isseen='$cf17_isseen',
sc17_cf_id='$sc17_cf_id',
cf17_pdp='$cf17_pdp',
cf17_redflag='$cf17_redflag',
cf18_score='$cf18_score',
cf18_isseen='$cf18_isseen',
sc18_cf_id='$sc18_cf_id',
cf18_pdp='$cf18_pdp',
cf18_redflag='$cf18_redflag',
cf19_score='$cf19_score',
cf19_isseen='$cf19_isseen',
sc19_cf_id='$sc19_cf_id',
cf19_pdp='$cf19_pdp',
cf19_redflag='$cf19_redflag',
cf20_score='$cf20_score',
cf20_isseen='$cf20_isseen',
sc20_cf_id='$sc20_cf_id',
cf20_pdp='$cf20_pdp',
cf20_redflag='$cf20_redflag',
cfcomments='$cfcomments',
redflagnotify='$redflagnotify'
where id='$id'");
which are called with
Code:
$result = $dbStuff->insertCF('',$_POST['1score'],$_POST['1isseen'],$_POST['1scenario'],$_POST['1pdp'],$_POST['1redflag'],$_POST['2score'],$_POST['2isseen'],$_POST['2scenario'],$_POST['2pdp'],$_POST['2redflag'],$_POST['3score'],$_POST['3isseen'],$_POST['3scenario'],$_POST['3pdp'],$_POST['3redflag'],$_POST['4score'],$_POST['4isseen'],$_POST['4scenario'],$_POST['4pdp'],$_POST['4redflag'],$_POST['5score'],$_POST['5isseen'],$_POST['5scenario'],$_POST['5pdp'],$_POST['5redflag'],$_POST['6score'],$_POST['6isseen'],$_POST['6scenario'],$_POST['6pdp'],$_POST['6redflag'],$_POST['7score'],$_POST['7isseen'],$_POST['7scenario'],$_POST['7pdp'],$_POST['7redflag'],$_POST['8score'],$_POST['8isseen'],$_POST['8scenario'],$_POST['8pdp'],$_POST['8redflag'],$_POST['9score'],$_POST['9isseen'],$_POST['9scenario'],$_POST['9pdp'],$_POST['9redflag'],$_POST['10score'],$_POST['10isseen'],$_POST['10scenario'],$_POST['10pdp'],$_POST['10redflag'],$_POST['11score'],$_POST['11isseen'],$_POST['11scenario'],$_POST['11pdp'],$_POST['11redflag'],$_POST['12score'],$_POST['12isseen'],$_POST['12scenario'],$_POST['12pdp'],$_POST['12redflag'],$_POST['13score'],$_POST['13isseen'],$_POST['13scenario'],$_POST['13pdp'],$_POST['13redflag'],$_POST['14score'],$_POST['14isseen'],$_POST['14scenario'],$_POST['14pdp'],$_POST['14redflag'],$_POST['15score'],$_POST['15isseen'],$_POST['15scenario'],$_POST['15pdp'],$_POST['15redflag'],$_POST['16score'],$_POST['16isseen'],$_POST['16scenario'],$_POST['16pdp'],$_POST['16redflag'],$_POST['17score'],$_POST['17isseen'],$_POST['17scenario'],$_POST['17pdp'],$_POST['17redflag'],$_POST['18score'],$_POST['18isseen'],$_POST['18scenario'],$_POST['18pdp'],$_POST['18redflag'],$_POST['19score'],$_POST['19isseen'],$_POST['19scenario'],$_POST['19pdp'],$_POST['19redflag'],$_POST['20score'],$_POST['20isseen'],$_POST['20scenario'],$_POST['20pdp'],$_POST['20redflag'],$_POST['comments'],$_POST['redflagnotify']);
$result = $dbStuff->updateCF($_POST['1score'], $_POST['1isseen'], $_POST['1scenario'], $_POST['1pdp'], $_POST['1redflag'],$_POST['2score'], $_POST['2isseen'], $_POST['2scenario'], $_POST['2pdp'], $_POST['2redflag'],$_POST['3score'], $_POST['3isseen'], $_POST['3scenario'], $_POST['3pdp'], $_POST['3redflag'],$_POST['4score'], $_POST['4isseen'], $_POST['4scenario'], $_POST['4pdp'], $_POST['4redflag'],$_POST['5score'], $_POST['5isseen'], $_POST['5scenario'], $_POST['5pdp'], $_POST['5redflag'],$_POST['6score'], $_POST['6isseen'], $_POST['6scenario'], $_POST['6pdp'], $_POST['6redflag'],$_POST['7score'], $_POST['7isseen'], $_POST['7scenario'], $_POST['7pdp'], $_POST['7redflag'],$_POST['8score'], $_POST['8isseen'], $_POST['8scenario'], $_POST['8pdp'], $_POST['8redflag'],$_POST['9score'], $_POST['9isseen'], $_POST['9scenario'], $_POST['9pdp'], $_POST['9redflag'],$_POST['10score'], $_POST['10isseen'], $_POST['10scenario'], $_POST['10pdp'], $_POST['10redflag'], $_POST['11score'], $_POST['11isseen'], $_POST['11scenario'], $_POST['11pdp'], $_POST['11redflag'],$_POST['12score'], $_POST['12isseen'], $_POST['12scenario'], $_POST['12pdp'], $_POST['12redflag'],$_POST['13score'], $_POST['13isseen'], $_POST['13scenario'], $_POST['13pdp'], $_POST['13redflag'],$_POST['14score'], $_POST['14isseen'], $_POST['14scenario'], $_POST['14pdp'], $_POST['14redflag'],$_POST['15score'], $_POST['15isseen'], $_POST['15scenario'], $_POST['15pdp'], $_POST['15redflag'],$_POST['16score'], $_POST['16isseen'], $_POST['16scenario'], $_POST['16pdp'], $_POST['16redflag'],$_POST['17score'], $_POST['17isseen'], $_POST['17scenario'], $_POST['17pdp'], $_POST['17redflag'],$_POST['18score'], $_POST['18isseen'], $_POST['18scenario'], $_POST['18pdp'], $_POST['18redflag'],$_POST['19score'], $_POST['19isseen'], $_POST['19scenario'], $_POST['19pdp'], $_POST['19redflag'],$_POST['20score'], $_POST['20isseen'], $_POST['20scenario'], $_POST['20pdp'], $_POST['20redflag'], $_POST['comments'],$_POST['redflagnotify'],$_POST['id']);