zhhealthcare wrote on Friday, May 14, 2010:
Hi Guys,
There is a potential bug in the working of the forms.
It occurs when we insert data.For the case of modification this issue does’t occur.
Consider the inbuilt form ‘misc_billing_options’.
We have uploaded it in the bug tracker: http://sourceforge.net/tracker/?func=detail&atid=1245239&aid=3001651&group_id=60081
save.php of the form folder has a code as follows at line 14
foreach ($_POST as $k => $var) {
$_POST = mysql_escape_string($var);
echo “$var\n”;
}
So now the internal array pointer of the array $_POST is moved to the last position.
For details Search ‘internal array pointer’ at http://php.net/manual/en/control-structures.foreach.php
Now the same array $_POST is passed to the function ‘formSubmit’ at line 21 as below.
$newid = formSubmit(“form_misc_billing_options”, $_POST, $_GET, $userauthorized);
This function is written in the library/api.inc file at line 32 as follows
function formSubmit ($tableName, $values, $id, $authorized = “0”)
The variable $values is now the $_POST
At line 35 there is a code while(list($key, $value) = each($values))
As the internal array pointer is at last position only the last value will be saved to the database.
Implication
The loop will be runned only once.It will not be looping the entire array elements.
Solution
Either instead of while loop use foreach.
For details see second Search result ‘internal array pointer’ at http://php.net/manual/en/control-structures.foreach.php
or add
reset($values);
to reset the file pointer before each while(if array is being manipulated as above.)
For details see search ‘26-Feb-2002 10:42’ at http://php.net/manual/en/control-structures.while.php
Basically the reason for the problem is foreach automatically initializes the pointer to first position where as while will not do that.
Thanks
Paul