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




        //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'] ?>">

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

                //LOAD NEWS

                $result = mysql_query("SELECT * FROM page") or die(mysql_error());
                <table id="admintable" border="1" cellpadding="2" cellspacing="0">
                    while ($data = mysql_fetch_array($result)){

                            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>';



Recommended Answers

Echo out your variables before the if to see if they are set correctly.

Jump to Post

All 3 Replies

Echo out your variables before the if to see if they are set correctly.

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 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.