dynamic adding record with dynamic forms
Posted: Fri Feb 18, 2005 4:16 am
Hi all;
I have a dynamically created form which updates a table using the following code I can almost achieve it:
but the problem is when I try and run an update using this form with the following code:
I then getting the following error:
Anyways any help would be appreciated.
THanks
I have a dynamically created form which updates a table using the following code I can almost achieve it:
Code: Select all
<?php
for($y=0; $y < $dbfield_num; $y++) {
$field_name = mysql_field_name($dbfields, $y);
echo("<tr><td><strong>$field_name</strong></td><td><input type='text' name='Fieldї]' id='Fieldї]'></td></tr>");
}
?>but the problem is when I try and run an update using this form with the following code:
Code: Select all
if ((isset($_POSTї"MM_insert"])) && ($_POSTї"MM_insert"] == "form1")) {
//************************************************
//list all fileds for user and write to database
$dbfields = mysql_list_fields($database_RespondNow, $tbl, $RespondNow);
$dbfield_num = mysql_num_fields($dbfields);
//echo $dbfield_num;
$y=0;
$fieldArray='';
foreach ($_POSTї'Field'] as $Field_num => $Field_value) {
$y++;
їb]LINE 55: $field_name = mysql_field_name($dbfields, $y);ї/b]//echo $field_name;
$fieldArray .="'$Field_value',";
//$EmailBody .="$field_name: $Field_value\n";
}
$fieldArray=rtrim($fieldArray,',');
$sql = mysql_query("INSERT INTO $tbl VALUES (NULL,$fieldArray)");
echo $sql;
if (!$sql) {
echo ('error'.mysql_error());
}I think it has something to do with the amount of rows b'cos when I echo the column headings out it doesn't give me the ID column so thats a mismatch with the insert row column amountWarning: mysql_field_name() [function.mysql-field-name]: Field 5 is invalid for MySQL result index 11 in C:\Program Files\Apache Group\Apache2\htdocs\respondnow\Admin\addinfo.php on line 55
errorColumn count doesn't match value count at row 1
Anyways any help would be appreciated.
THanks