Notice: Undefined variable: confirmation in C:\xampp\htdocs\RustoleumCustomCMS\administrator\admin.php on line 126

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

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

?>
<div align="center">
    <div style="width:700px;text-align:left;padding-top:5px;">
        <?php 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 static_page") or die(mysql_error());
                ?>
                <table border="1" cellpadding="2" cellspacing="0">
                    <tr>
                        <th>Static Page</th><th>Judul</th><th>Action</th>
                    </tr>
                    <?php
                    while ($data = mysql_fetch_array($result)){
                        echo '<tr>';
                            echo '<td>'.$data['page'].'</td>';
                            echo '<td>'.$data['judul'].'</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>';
                    }
                    ?>
                </table>

line 126: <?php echo $confirmation; ?>

What puzzles you ? Why $confirmation is undefined ? You define , it inside two conditional statements so logically those conditions are not satisfied.

It doesn't work, huh? Well, basically I am trying to say if that data is successfully deleted than the first text shows up otherwise the second one.

It's a confirmation whether the data is successfully deleted or not.

In this case you don’t need two separate ifs.

Example without changing the way you have thought it.

if ( (!empty($_REQUEST['id']) && !empty($_REQUEST['mode'])) && $_REQUEST['mode'] == "delete")
{
    $id = $_REQUEST['id'];
    $result = mysql_query("DELETE FROM static_page WHERE id =".$id) or die(mysql_error());
    $confirmation = ($result) ? "Data telah terhapus." : "Gagal menghapus data.";
}
else 
{
  $confirmation = "No change performed"; 
}

According to me delete querry of sql does not return anything.Whether the querry is correct or not could be checked by values in database...Insert/delete querries don't return any value

Generally, undefined variable means that it has no value and it is just a warning, change to this:

<?php if (isset($confirmation)) { echo $confirmation; } ?>

This should get rid of the warning but doesn't help as to why the variable is empty.

Then for your if statement shpould work like this:

$confirmation = !$result ? "Data telah terhapus." : "Gagal menghapus data.";
// or whichever way round you need it

The error disappeared. Message : No change performed

Why is it? It suppose to delete the row.

it is not going in the following if condition

if ( (!empty($_REQUEST['id']) && !empty($_REQUEST['mode'])) && $_REQUEST['mode'] == "delete")

add 3 lines before if and see what if gives in request array, copy and paste that output here.

echo "<pre>"
print_r($_REQUEST);
echo "</pre>";
if ( (!empty($_REQUEST['id']) && !empty($_REQUEST['mode'])) && $_REQUEST['mode'] == "delete")
{
.......

Array
(
)

if I press Hapus(delete) this shows up:

Array
(
    [mode] => delete
    [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.