1

I have a problem after inserting some data from array, the insert data works properly. But the Redirect doesn't work, I don't understand the error, because no error message show just the blank page, I have tried and tried until it become habit that makes me tired.

Here is the Function Controller that I use:

public function all() {
    $data       = array();
    $idkelas    = $this->input->post('kelas');
    $idabsen    = $this->input->post('idabsensi');
    $idabsen2   = $this->input->post('idabsen');
    $id         = $this->input->post('idsiswa');
    $hadir  = $this->input->post('hadir');
    $smt        = $this->input->post('semester');
    $jamke  = $this->input->post('jamke');

    $count      = count($id);
    // to absensi
    $this->db->query("UPDATE absensi SET jmlhadir = '$count' WHERE idabsensi = '$idabsen2'");

    // to absensidetail
    for($j=0; $j < (int)($count); $j++) {
        $data[] = array(
            'idabsensi'     => $idabsen[$j],
            'idsiswa'       => $id[$j],
            'statusabsen'   => $hadir[$j],
            'semester'      => $smt[$j],
            'jamke'         => $jamke[$j]
            );
        }
        return $this->db->insert_batch('absensidetail', $data);
        redirect('absensi/absen/pilihkelas/'.$idkelas, 'refresh');

}

This is the View:

<form action="<?php echo base_url()?>absensi/absen/all" method="post">
<input type="submit" class="btn btn-info btn-large" value="ABSENT ALL" />
<table class="table table-striped table-bordered table-condensed">
            <thead>
                <tr>
                    <th>No.</th>
                    <th>No. Induk</th>
                    <th>Student Name</th>
                    <th>Gender</th>
                    <th>State</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
            <?php $i=0 ?>
            <?php foreach($kel as $d):
            $i++;
            ?>
            <tr class="list-users">
                <td><input type="hidden" name="idsiswa[]" value="<?=$d->idsiswa?>" readonly><?=$d->idsiswa?></td>
                <td><input type="hidden" name="hadir[]" value="hadir" readonly><input type="hidden" name="jamke[]" value="<?=$jamke?>" readonly><input type="hidden" name="mapel" value="<?=$idmapel?>" readonly><?=$d->noinduk?></td>
                <td><input type="hidden" name="kelas" value="<?=$d->kelas?>" readonly><input type="hidden" name="semester[]" value="<?=$h_getsmt->idsemester?>" readonly><?=$d->namasiswa?></td>
                <td><input type="hidden" name="idabsensi[]" value="<?=$d->idabsensi?>" readonly><input type="hidden" name="idabsen" value="<?=$d->idabsensi?>" readonly><?=$d->jeniskelamin?></td><td><span class="label label-unabsent">unabsent</span></td>
                <td>
                    <div class="btn-group">
                        <a class="btn btn-mini dropdown-toggle" data-toggle="dropdown" href="#">Actions <span class="caret"></span></a>
                        <ul class="dropdown-menu">
                            <li><a ><i class="icon-pencil"></i>Press Button<BR>ABSENT ALL First</a></li>
                        </ul>
                    </div>
                </td></tr>
            <?php endforeach ?>
            </tbody>
        </table>
     </form>

I really hope someone can help me. Thank You

2 Answers2

1

The redirect would need to come before return

This is from php.net:

If called from within a function, the return statement immediately ends execution of the current function, and returns its argument as the value of the function call. return also ends the execution of an eval() statement or script file.

You can also check out: How to make a redirect in PHP?

Community
  • 1
  • 1
Mikolaj
  • 688
  • 8
  • 19
  • I just tried The Redirect come before `return`. But the Insert Batch doesn't work. Anyway, thanks for the reference link its valuable for me, let me learn. – Dindon fiqri aji Feb 02 '15 at 16:13
  • @Dindonfiqriaji `redirect` will send you to the page (you are redirecting to) before `return` can be executed. You might consider not `return`'ing and instead calling the object (minus `return`) and then the `redirect`. – Mikolaj Feb 02 '15 at 16:16
0

Remove return from the statement for batch insert. If there is return, it will not go to the next statement written for redirection.

Update it like this.

$this->db->insert_batch('absensidetail', $data);
redirect('absensi/absen/pilihkelas/'.$idkelas, 'refresh');
Mansoorkhan Cherupuzha
  • 1,761
  • 1
  • 24
  • 45
  • Its work! How can just remove the `return` ? arghh I was thinking over night over day about it. I really don't think about remove the `return`. Oh I'm feel I must learn much much much more. Thank you very much.... – Dindon fiqri aji Feb 05 '15 at 03:06