I have written a function that is supposed to be able to generate a number of input fields which will be commonly used in a private web application.
Details of these fields are stored in the mysql database. There is a varchar field which holds the name of the function that generates the related text for a dropdown, as well as the associative key to retrieve the right string from the function's result.
The variable function name does not call the function. It worked in an earlier simplified iteration using only mysqli_fetch_row rather than mysqli_fetch_assoc.
I'd like to get it working with associative keys. (I can see no reason why associative keys could be the problem).
I've tried various forms of eval and exec. I can get a lite version to work with mysqli_fetch_row.
I have followed instructions here: Store function name in database and then execute it
I haven't been able to find anything else that directly adresses the problem.
$funcResult = $func($fldNmValue)[$funcKey];
doesnt't work
$funcResult = rank($fldNmValue)[$funcKey];
works
'rank' is one of the function names in the database
it is pulled from the database by:
$query = "SELECT fieldFunction,fieldFunctionKey FROM fieldType WHERE fieldTypeId='$fldTypeId'";
$result = db_query($query);
$data = db_fetch_assoc($result);
$func = $data['fieldFunction'];
I have verified that $func contains valid function names like 'rank' or 'castDetails'.
printing "$func($fldNmValue)" gives, for example:
castDetails(2)
as expected.
PHP refuses to execute $funcResult = $func($fldNmValue)[$funcKey];
and simply exits.
I had expected it to function like it did when using mysqli_fetch_rows.