tektipsismyfavorite
Technical User
I'm trying to write "user-added" fields to MySQL and can't figure out how to go about this.
The form has dynamically added fields and they're added in this method:
field2 <- starts at 2
field3
field4
When a field is added or removed from the page, i update a hidden input (visibleFields) with the values:
2,3,4,
Then I use this code when the form is processed:
Now I'm not sure what to do and how to write this to the database. right now, my code is:
Somehow I need to use the index of vParray rather than i to get the field number. Any ideas?
The form has dynamically added fields and they're added in this method:
field2 <- starts at 2
field3
field4
When a field is added or removed from the page, i update a hidden input (visibleFields) with the values:
2,3,4,
Then I use this code when the form is processed:
Code:
$vParray = split(",",$_POST['visibleFields']);
$total = count($vParray);
Now I'm not sure what to do and how to write this to the database. right now, my code is:
Code:
if($_POST['visibleFields'] != ""){
for($i=2;$i <= $total+1; $i++){
if($_POST['field'.$i] != ""){
$insertSQL = sprintf("INSERT INTO mytable (field) VALUES (%s)",
GetSQLValueString($_POST['field'.$i], "text"));
}
mysql_select_db($database, $connection);
$Result = mysql_query($insertSQL, $connection) or die(mysql_error());
}
}
Somehow I need to use the index of vParray rather than i to get the field number. Any ideas?