I'm a newbie in PHP, I have a dynamic textbox which looks like these

name="name1"
name="name2"
name="name3"

the number of fields depends on how many user wants but the problem is on the SQL script, I need to put the $ctr besides "$_POST[name]" in order for the compiler see all my fields.

for ( $ctr = 1; $ctr <= 10; $ctr += 1) 
    {
    $sql = "INSERT INTO siblings (name) VALUES ('$_POST[name]')";    
    }‚Äč

the problem is how to place the variable besides "$_POST[name]"

Thank you Guys!

- joel

you can't use such model as

name="name1"
name="name2"
name="name3"

you can use array

name[]="name1"
name[]="name2"
name[]="name3"

for name of your textbox set name="name[]" after that in post it will come over as array


Know that one string as name cannot be equal to 3 different values at the same time. Only possible way is to use array.
And after that into the POST you will get this array value.

Member Avatar
diafol

sv3tli0 has it on the array.
When you come to use the SQL, build the VALUES from - something like this (not tested):

function clean($array) {
    return array_map('mysql_real_escape_string', $array);
}
$names = clean($_POST['name']); 
$nstr = implode("'),('",$names);
$sql = "INSERT INTO siblings (name) VALUES ('$nstr')";