0

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

5
Contributors
11
Replies
12
Views
4 Years
Discussion Span
Last Post by davy_yg
0

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

0

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.

Edited by davy_yg

0

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"; 
}
0

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

0

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
0

The error disappeared. Message : No change performed

Why is it? It suppose to delete the row.

0

it is not going in the following if condition

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

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")
{
.......
0

if I press Hapus(delete) this shows up:

Array
(
    [mode] => delete
    [id] => 0
)

Edited by davy_yg

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.