Jump to content

[SOLVED] $_Post only send first dynamic field to DB


StefanRSA

Recommended Posts

I created a form with dynamic fields. The field types and names are created and saved in a DB.

I then populate a form with the dynamic field as well as a few standard fields.

One field set is a checkbox and the other short text.

When I try to send the $_Post of the dynamic fields to the DB only the first field is send to the DB.

What am I doing wrong?

 

My Code to get a handle on the Dynamic fields is working as follow:

$query = mysql_query("SELECT * FROM field_name WHERE sub_id = '$adsubcat'") or die(mysql_error());
while($rows = mysql_fetch_array($query)){
$ftype= $rows['field_type'];
$ftitle= $rows['field_title'];
$f_id = $rows['id'];
$fname= $rows['field_name'];
$fcomp= $rows['compulsory'];
$fval= $rows['val'];
$fhelp= $rows['help'];
$fid= $rows['help'];
///Posted field start here
$postedfield =trim($_POST[$fname]);
/////////////////////////////////////////SELECT BOX FIELD START/////////////////////
if ($ftype=='select'){
$c=$_REQUEST["$fname"];
for($i=0;$i<count($c);$i++)
{
$val=$c[$i];
$sql="INSERT INTO adfields(adid, f_id, f_title, f_name, f_type, f_value, ad_user)
VALUES ('$adnr', '$f_id', '$ftitle', '$fname', '$ftype','$val','$userid')";
$res=mysql_query($sql);
echo $val;
}
}
/////////////////////////////////////////SELECT BOX FIELD END //////////////////////
else {
//// ALL OTHER FIELDS START
$query = mysql_query("INSERT INTO adfields (adid, f_id, f_title, f_name, f_type, f_value, ad_user) 
VALUES ('$adnr', '$f_id', '$ftitle', '$fname', '$ftype', '$postedfield','$userid')") or die(mysql_error());
//// ALL OTHER FIELDS ENDS
}
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.