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
}
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.