Inserting more than one row with data not showing

129
September 05, 2017, at 2:40 PM

Inserting more than one row with data didn't showing as in the picture, also when pressing save with not inserting any new rows showing so many errors. The HTML and PHP code shown below :

Notice: Undefined index: field11 in C:\Program Files (x86)\Apache2.2\htdocs\hr\setup\manage_department_sub.php on line 65

Notice: Undefined index: field41 in C:\Program Files (x86)\Apache2.2\htdocs\hr\setup\manage_department_sub.php on line 65

Notice: Undefined index: attendancegrp1 in C:\Program Files (x86)\Apache2.2\htdocs\hr\setup\manage_department_sub.php on line 65 insert into hr_departments (code,descr,lang,head,attendancegrp) values (17,'',0,'','') Notice: Undefined index: field11 in C:\Program Files (x86)\Apache2.2\htdocs\hr\setup\manage_department_sub.php on line 68 insert into listsvalues (id,listid,userid,descr,lang,seq) values (17,41,-1,'',0,17) Notice: Undefined index: field21 in C:\Program Files (x86)\Apache2.2\htdocs\hr\setup\manage_department_sub.php on line 71

<?php
session_start();
?>
<?php
header("Content-Type: text/html;charset=windows-1256");
include_once ('../includes/header_config.php');
$sorting = ' order by depe asc';
if (isset($_POST['field']))
{
    if ($_POST['field'] != '')
    {
        $sorting = ' order by ' . $_POST['field'];
    }
    else
    {
        $sorting = ' ';
    }
}
?>

<?php
//delete
if (isset($_POST['action']) && ($_POST['action'] == 3))
{
    $sql = "select *  from glb_teachers where department=" . $_POST['delid'];
    $qry = DB_query($sql, $db);
    if (DB_num_rows($qry) == 0)
    {
        $sql = "delete from hr_departments where code=" . $_POST['delid'];
        $qry = DB_query($sql, $db);
        $sql = "delete from listsvalues where listid=41 and id=" . $_POST['delid'];
        $qry = DB_query($sql, $db);
        $sql = "delete from hrnodes  where contactid = '" . $_POST['delid'] . "' and userid=12";
        $result2 = DB_query($sql, $db);
        $sql = "delete from paynodes  where contactid = '" . $_POST['delid'] . "' and userid=12";
        $result2 = DB_query($sql, $db);
    }
}
?>


<?php
//insert
if (isset($_POST['action']) && ($_POST['action'] == 2))
{
    if ($_POST['invoicebreakdown'] == '' || $_POST['invoicebreakdown'] == 0) $invoice_breakdown = 1;
    else $invoice_breakdown = $_POST['invoicebreakdown'];
    for ($i = 1;$i <= $invoice_breakdown;$i++)
    {
        if (isset($_POST['cur_id_' . $i]) && $_POST['cur_id_' . $i] != '') $cur_id = $_POST['cur_id_' . $i];
        else $cur_id = '';
        // Insert the value if the cur_id is null
        if ($cur_id == '')
        {
            $sql = "select max(code) as maxid from hr_departments ";
            $qry = DB_query($sql, $db);
            if ($res = DB_fetch_array($qry))
            {
                if ($res[0] != NULL and $res[0] > 0)
                {
                    $newid = $res[0] + 1;
                }
                else
                {
                    $newid = 1;
                }
            }
            echo $sql = "insert into hr_departments (code,descr,lang,head,attendancegrp) values (" . $newid . ",'" . $_POST['field1' . $i] . "',0,'" . $_POST['field4' . $i] . "','" . $_POST['attendancegrp' . $i] . "')";
            $result = DB_query($sql, $db);
            echo $sql = "insert into listsvalues (id,listid,userid,descr,lang,seq) values (" . $newid . ",41,-1,'" . $_POST['field1' . $i] . "',0," . $newid . ")";
            $result = DB_query($sql, $db);
            echo $sql = "insert into hr_departments (code,descr,lang,head,attendancegrp) values (" . $newid . ",'" . $_POST['field2' . $i] . "',2,'" . $_POST['field4' . $i] . "','" . $_POST['attendancegrp' . $i] . "')";
            $result = DB_query($sql, $db);
            echo $sql = "insert into listsvalues (id,listid,userid,descr,lang,seq) values (" . $newid . ",41,-1,'" . $_POST['field2' . $i] . "',2," . $newid . ")";
            $result = DB_query($sql, $db);
            echo $sql = "insert into hr_departments (code,descr,lang,head,attendancegrp) values (" . $newid . ",'" . $_POST['field3' . $i] . "',1,'" . $_POST['field4' . $i] . "','" . $_POST['attendancegrp' . $i] . "')";
            $result = DB_query($sql, $db);
            echo $sql = "insert into listsvalues (id,listid,userid,descr,lang,seq) values (" . $newid . ",41,-1,'" . $_POST['field3' . $i] . "',1," . $newid . ")";
            $result = DB_query($sql, $db);
            $sql = "select * from usr_users where id=" . $_SESSION['userid'];
            $result2 = DB_query($sql, $db);
            $newid2 = DB_fetch_array($result2);
            if ($newid2['hr_dept'] != - 1)
            {
                $sql = "update usr_users set hr_dept=hr_dept+'," . $newid . "' where id=" . $_SESSION['userid'];
                $result2 = DB_query($sql, $db);
            }
            $sql = "select max(id) as mx from hrnodes ";
            $result1 = DB_query($sql, $db);
            $newid1 = DB_fetch_array($result1);
            $nwd = $newid1['mx'] + 1;
            if ($_SESSION['lang'] == 0)
            {
                $name = $_POST['field1' . $i];
            }
            else if ($_SESSION['lang'] == 1)
            {
                $name = $_POST['field2' . $i];
            }
            else
            {
                $name = $_POST['field3' . $i];
            }
            $sql = "insert into hrnodes (id,userid,title,position,parentid,contactid,acyear) VALUES 
('" . $nwd . "','12',N'" . $name . "','0','1','" . $newid . "',N'')";
            $result2 = DB_query($sql, $db);
        }
        else
        {
            $sql = "update hr_departments set descr='" . $_POST['field1' . $i] . "',head = '" . $_POST['field4' . $i] . "',attendancegrp='" . $_POST['attendancegrp' . $i] . "' where code =" . $_POST['cur_id_' . $i] . " and lang = 0";
            $result = DB_query($sql, $db);
            $sql = "update listsvalues set descr='" . $_POST['field1' . $i] . "' where listid=41 and id =" . $_POST['cur_id_' . $i] . " and lang = 0";
            $result = DB_query($sql, $db);
            $sql = "update hr_departments set descr='" . $_POST['field2' . $i] . "',head = " . $_POST['field4' . $i] . ",attendancegrp='" . $_POST['attendancegrp' . $i] . "' where code =" . $_POST['cur_id_' . $i] . " and lang = 1";
            $result = DB_query($sql, $db);
            $sql = "update listsvalues set descr='" . $_POST['field2' . $i] . "' where listid=41 and id =" . $_POST['cur_id_' . $i] . " and lang = 1";
            $result = DB_query($sql, $db);
            $sql = "update hr_departments set descr='" . $_POST['field3' . $i] . "',head = " . $_POST['field4' . $i] . ",attendancegrp='" . $_POST['attendancegrp' . $i] . "' where code =" . $_POST['cur_id_' . $i] . " and lang = 2 ";
            $result = DB_query($sql, $db);
            $sql = "update listsvalues set descr='" . $_POST['field3' . $i] . "' where listid=41 and id =" . $_POST['cur_id_' . $i] . " and lang = 2";
            $result = DB_query($sql, $db);
            if ($_SESSION['lang'] == 0)
            {
                $name = $_POST['field1' . $i];
            }
            else if ($_SESSION['lang'] == 1)
            {
                $name = $_POST['field2' . $i];
            }
            else
            {
                $name = $_POST['field3' . $i];
            }
            //$sql = "update glb_teachers set category=".$_POST['acad']." where department =".$_POST['cur_id_'.$i]."  and (isnull(category,-1) =-1 or category='')";
            $result = DB_query($sql, $db);
            $sql = "update hrnodes set title='" . $name . "' where  contactid = '" . $_POST['cur_id_' . $i] . "' and userid=12";
            $result2 = DB_query($sql, $db);
            $sql = "update paynodes set title='" . $name . "' where  contactid = '" . $_POST['cur_id_' . $i] . "' and userid=12";
            $result2 = DB_query($sql, $db);
        }
    }
}
?>  






<?php
if ($_SESSION['hr_dept'] == - 1) $deptcond = '';
else $deptcond = ' and hr_departments.code in (' . $_SESSION['hr_dept'] . ') ';
if (!isset($_POST['breakdown'])) $_POST['breakdown'] = 0;
$sql = "SELECT distinct hr_departments.code,isnull (hr_departments.attendancegrp,-1) as attendancegrp, hr_departments.descr AS depe, hr_departments_1.descr AS depf, isnull (hr_departments.head,0) head, hr_departments_2.descr AS depa, glb_teachers.part1 + ' '+glb_teachers.part4 as name,glb_teachers.tch_id,hr_departments.accnby,listsvalues.descr as grp
FROM         hr_departments INNER JOIN
                      hr_departments hr_departments_1 ON hr_departments.code = hr_departments_1.code INNER JOIN
                      hr_departments hr_departments_2 ON hr_departments_1.code = hr_departments_2.code LEFT outer  JOIN
                      glb_teachers ON hr_departments.head = glb_teachers.tch_id LEFT outer  JOIN
                      listsvalues ON hr_departments.attendancegrp = listsvalues.id and listsvalues.listid=61 and listsvalues.lang=" . $_SESSION['lang'] . "  
WHERE  hr_departments.code<>-1 and (hr_departments.lang = 0) AND (hr_departments_2.lang = 2) AND (hr_departments_1.lang = 1)" . $sorting;
$result = DB_query($sql, $db);
$num_rows = DB_num_rows($result);
$tot = $_POST['breakdown'] + $num_rows;
$sql1 = "SELECT tch_id,part1,part4
FROM glb_teachers left outer join glb_laststatus on glb_teachers.laststatus=glb_laststatus.id and glb_laststatus.lang =0
WHERE glb_laststatus.active =1 ORDER BY part1,part4";
$result1 = DB_query($sql1, $db);
$sql2 = "select listsvalues.id, listsvalues.descr,lists.locked from listsvalues left outer join lists on listsvalues.listid=lists.listid and lists.lang=" . $_SESSION['lang'] . "  where listsvalues.listid=61 and listsvalues.lang=" . $_SESSION['lang'] . " and (listsvalues.userid=-1 or listsvalues.userid=1) order by case listsvalues.id when -1 then ' ' else listsvalues.descr end";
$result2 = DB_query($sql2, $db);
?>


<input type="hidden" name="amttype" value="" id="amttype">
<input type="hidden" name="invoicebreakdown" value="<?php echo $tot; ?>" id="invoicebreakdown">
<input type="hidden" name="subbreakdown" value="" id="subbreakdown">

<table width="95%" border="0"  cellpadding="5" cellspacing="0" class="table_fullwidth">
<tr><th width="15%">Department</th><th width="15%">Чсогу</th><th width="15%">Department</th>
<th width="19%">Head of Department</th><th width="15%">Shift Group</th>
<th width="16%">Allowance for Year</th>
</tr>
<?php $i = 1;
while ($myrow1 = DB_fetch_array($result))
{
    if ($i % 2 == 0) $bkg = 'td1';
    else $bkg = 'td2';
?>
<tr id="trow_<?php echo $i; ?>" class="<?php echo $bkg; ?> ">
<td align="center"><input type="hidden" name="cur_id_<?php echo $i; ?>" id="cur_id_<?php echo $i; ?>" value="<?php echo $myrow1['code']; ?>"> 
<input  type="text" name="field1<?php echo $i; ?>" id="field1<?php echo $i; ?>" class="sel_long1 required" value="<?php echo $myrow1['depe']; ?>" tabindex="<?php echo $i; ?>_1" > </td>
<td align="center"><input tabindex="<?php echo $i; ?>_2" class="sel_long1 required" type="text" name="field2<?php echo $i; ?>" id="field2<?php echo $i; ?>" value="<?php echo $myrow1['depf']; ?>">  </td>
<td align="center"><input tabindex="<?php echo $i; ?>_3" class="sel_long1" type="text" name="field3<?php echo $i; ?>" id="field3_<?php echo $i; ?>" value="<?php echo $myrow1['depa']; ?>"> </td>
<td align="center"><Select tabindex="<?php echo $i; ?>_4" name="field4<?php echo $i; ?>" id="field4_<?php echo $i; ?>" class="sel_long1">
<?php
    while ($row1 = DB_fetch_array($result1))
    { ?>
<option value="<?php echo $row1['tch_id']; ?>" <?php if ($myrow1['head'] == $row1['tch_id'])
        { ?> selected="selected" <?php
        } ?>  ><?php echo $row1['part1'] . ' ' . $row1['part4']; ?></option>
<?php
    } ?> </Select> </td>

<td align="center"><Select tabindex="<?php echo $i; ?>_5" name="attendancegrp<?php echo $i; ?>" id="attendancegrp_<?php echo $i; ?>" class="sel_long1">
<?php
    while ($row1 = DB_fetch_array($result2))
    { ?>
<option value="<?php echo $row1['id']; ?>" <?php if ($myrow1['grp'] == $row1['descr'])
        { ?> selected="selected" <?php
        } ?>  ><?php echo $row1['descr'] ?></option>
<?php
    } ?> </Select> </td>





<td align="center"><input tabindex="<?php echo $i; ?>_6" class="sel_long1" type="text" name="field6<?php echo $i; ?>" id="field6_<?php echo $i; ?>" value="<?php echo $myrow1['accnby']; ?>"> </td>
<td align="center"> <img src="<?php echo $site_path; ?>images/del.png" width="20" class="cur" title="Delete" onclick="deleteitem('<?php echo $myrow1['code']; ?>');"></td> 
</tr>
<?php
    $i++;
}
$breakdown = $_POST['breakdown'] + $num_rows;
$j = $num_rows + 1;
while ($j <= $breakdown)
{
    if ($j % 2 == 0) $bkg = 'td1';
    else $bkg = 'td2';
?>

<?php
    $sql1 = "SELECT tch_id,part1,part4
FROM glb_teachers left outer join glb_laststatus on glb_teachers.laststatus=glb_laststatus.id and glb_laststatus.lang =0
WHERE glb_laststatus.active =1 ORDER BY part1,part4";
    $result1 = DB_query($sql1, $db);
?>
<tr id="trow_<?php echo $j; ?>" class="<?php echo $bkg; ?> "><td align="center">
<input type="hidden" name="cur_id_<?php echo $j; ?>" id="cur_id_<?php echo $j; ?>" value="">
<input  type="text" name="field1<?php echo $j; ?>" id="field1<?php echo $j; ?>" class="sel_long1 required" value="" tabindex="<?php echo $j; ?>_1" > </td>
<td align="center" ><input  class="sel_long1 required" type="text" name="field2<?php echo $j; ?>" id="field2<?php echo $j; ?>" value="" tabindex="<?php echo $j; ?>_2"></td>
<td align="center"><input  class="sel_long1 required" type="text" name="field3<?php echo $j; ?>" id="field3<?php echo $j; ?>" value="" tabindex="<?php echo $j; ?>_3"> </td>
<td align="center"><Select tabindex="<?php echo $j; ?>_4" name="field4<?php echo $j; ?>" id="field4_<?php echo $j; ?>" class="sel_long1 required">
<option value="0" >N/A</option>
<?php
    while ($row1 = DB_fetch_array($result1))
    { ?>
<option value="<?php echo $row1['tch_id']; ?>"  ><?php echo $row1['part1'] . ' ' . $row1['part4']; ?></option>
<?php
    } ?>
</select></td>


    <td align="center"><Select tabindex="<?php echo $j; ?>_5" name="attendancegrp<?php echo $j; ?>" id="attendancegrp_<?php echo $j; ?>" class="sel_long1 required">
<?php $getl = DB_query("select listsvalues.id, listsvalues.descr,lists.locked from listsvalues left outer join lists on listsvalues.listid=lists.listid and lists.lang=" . $_SESSION['lang'] . "  where listsvalues.listid=61 and listsvalues.lang=" . $_SESSION['lang'] . " and (listsvalues.userid=-1 or listsvalues.userid=1) order by case listsvalues.id when -1 then ' ' else listsvalues.descr end ", $db);
?>
                      <?php while ($getitem = DB_fetch_array($getl))
    { ?>
                      <?php while ($getitem = DB_fetch_array($getl))
        { ?>
                      <option  value="<?php echo $getitem['id']; ?>"><?php echo $getitem['descr'] ?></option>
                      <?php
        }
    }
?>
</select></td>

<td align="center"><Select tabindex="<?php echo $j; ?>_6" name="field6<?php echo $j; ?>" id="field6<?php echo $j; ?>" class="sel_long1 required">
<?php $zyr = DB_query("select id, acyear, starty, endy from glb_acyear where isnull (hrlock,0)=0 and  isnull (paylock,0)=0 order by acyear desc", $db);
    while ($zy = DB_fetch_array($zyr))
    { ?><option value="<?php echo $zy['id']; ?>"><?php echo $zy['starty'] . ' - ' . $zy['endy']; ?></option><?php
    } ?></select>
    </select></td>  


<td align="center"><img src="<?php echo $site_path; ?>images/del.png" title="Delete"  onclick="delete_row_details(<?php echo $j; ?>)" width="20" class="cur"></td>
</tr>
<?php $j++;
} ?>
</table>
<div class="save_bt"><input  name="save" id="savebt" class="no_marright submit-green save_right" value="Save"  type="button" onclick="validate_save()" tabindex="<?php echo $j; ?>"> </div>
<div id="did1"></div>

<script>
 var $targets = $('#erp_from_sub').find('input, button , select'),
    steps = $targets.map(function() {
        return $(this).attr('tabindex');
    }).get();
$('#erp_from_sub').on('keypress', 'input, button, select', function(e) {
    if (e.keyCode == 13) {
        var current = $.inArray($(this).attr('tabindex'), steps),
            next = steps[++current % steps.length];
        $targets.filter('[tabindex="' + next + '"]').focus();
    }
});
function deleteitem(a) {
  if(confirm('Are you sure you want delete?')) { document.erp_from_sub.delid.value=a;  document.getElementById('action').value='3';load_subpage('erp_from_sub');}
  }
  function delete_row_details(id)
{
var el = document.getElementById('trow_'+id);
if(confirm("Are you sure you want to delete this row")==true)
el.parentNode.removeChild(el);
/*calculateSum_credit();*/
}
</script>
READ ALSO
One of two ajax functions not working

One of two ajax functions not working

in this code snippet, I want to load form the view folder (MVC project) based on a selected option in a select tag using ajax and it works correctlyWhat I want, is when I click on the submit button, that it alerts me the content of test

122
Trigger a pageview in Apache log from PHP

Trigger a pageview in Apache log from PHP

From PHP code, I would like to trigger a dummy / virtual pageview that would appear in the Apache log file other_vhosts_accesslog:

112
Displaying table row information into single line with table

Displaying table row information into single line with table

I need helpI want to display one column data in a single row as table information

111