Quote:
but I think we should Work it yet to find a solution.
As
I suggested earlier, the best way to see what is wrong is to debug it, i.e. to set a breakpoint and check the status of the variables. Then you can see if your logic is correct and you have what you expect.
That's what I did, and it seems that your issue is that the "$table_nbfields" variable is empty at the point when you get to this code:
if ($table_nbfields > 0) {
$datas = array();
for( $i = 0; $i < $table_nbfields; $i++ ) {
$datas[] = array('field_mid' => $table_mid[$i],
'field_tid' => $table_id[$i],
'field_numb' => $table_nbfields[$i],
'field_name' => $_POST['field_name'][$i],
'field_type' => $_POST['field_type'][$i],
'field_value' => $_POST['field_value'][$i],
'field_attribute' => $_POST['field_attribute'][$i],
'field_null' => $_POST['field_null'][$i],
'field_default' => $_POST['field_default'][$i],
'field_key' => $_POST['field_key'][$i],
'field_autoincrement' => (($_REQUEST['field_autoincrement'][$i] == 1) ? '1' : '0'),
'field_element' => $_POST['field_element'][$i],
'field_inlist' => (($_REQUEST['field_inlist'][$i] == 1) ? '1' : '0'),
'field_inform' => (($_REQUEST['field_inform'][$i] == 1) ? '1' : '0'),
'field_admin' => (($_REQUEST['field_admin'][$i] == 1) ? '1' : '0'),
'field_user' => (($_REQUEST['field_user'][$i] == 1) ? '1' : '0'),
'field_block' => (($_REQUEST['field_block'][$i] == 1) ? '1' : '0'),
'field_main' => (($i == $_REQUEST['field_main']) ? '1' : '0'),
'field_search' => (($_REQUEST['field_search'][$i] == 1) ? '1' : '0'),
'field_required' => (($_REQUEST['field_required'][$i] == 1) ? '1' : '0')
);
}
foreach ($datas as $value) {
$obj->setVars( $value );
$fieldsHandler->insert($obj);
}
}
so this:
if ($table_nbfields > 0)
will never be true and you will never get to the code that you have shown us. And of course, you will never be able to test any changes you are making to it.
You define the variable as:
$table_nbfields = TDMCreate_CleanVars($_REQUEST, 'table_nbfields');
But there is no variable of this name in the $_REQUEST.
There is the "field_numb", which seems to be the one that you're should be using.
Fix that, and then you'll be able to see if the whole array issue is working or not.
Always check your logic to make sure that you are getting what you expect to get, and that's why tools like
PHPUnit are so helpful