I wonder when I press hapus / delete nothing happens. It suppose to delete 1 row in table page.

admin.php

<?php         

      include('../includes/koneksi.php');



        //Hapus berita // undefined index: mode



    if (!empty($_REQUEST['id']) && !empty($_REQUEST['mode']) && $_REQUEST['mode'] == "delete")
        {
        $id = $_REQUEST['id'];
        $result = mysql_query("DELETE FROM page WHERE id =".$id) or die(mysql_error());

        $confirmation = !$result ? "Gagal menghapus data." : "Data telah terhapus."; 
        }


?>
<div align="center">
    <div style="width:700px;text-align:left;padding-top:5px;">
        <?php  if (isset($confirmation)) { echo $confirmation; } ?>  
        <form method="get" action="<?php $_SERVER['PHP_SELF'] ?>">

                                    <br/>
                        <a class="topLink" href="input_berita_static.php">Berita Static Baru >></a><br><br>

        <?php
                //LOAD NEWS

                $result = mysql_query("SELECT * FROM page") or die(mysql_error());
                ?>
                <table id="admintable" border="1" cellpadding="2" cellspacing="0">
                    <tr>
                        <th>Page</th><th>Lokasi</th><th>Action</th>
                    </tr>
                    <?php
                    $i=0;
                    while ($data = mysql_fetch_array($result)){
                    $result2=($i%2)?'#DFA09D':'white';

                            echo "<tr bgcolor='$result2'>";                  
                            echo '<td>'.$data['judul'].'</td>';
                            echo '<td>Home1</td>';
                            echo '<td><a href="admin.php?mode=delete&id='.$data['id'].'">Hapus</a> |<a href="input_berita_static.php?id='.$data['id'].'">Edit</a></td>';
                        echo '</tr>';

                    $i++;   
                    }
                    ?>
                </table>

        </form>
    </div>
</div>
  </center>
</div>  

Recommended Answers

All 3 Replies

Apart from the undefined, see the manual for empty. I quote: "Returns FALSE if var exists and has a non-empty, non-zero value. Otherwise returns TRUE". Your code won't work for id=0

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.