Hi guys, can you help me to solve my problem. i have create coding table for my database. i mean i have a form and when user fill in their information into the form, the data will store in this table(coding). but unfortunately, in this coding, my delete button are not working. Honestly i'm still noob with php coding,and i get this coding from other page and try to change it. but i get this problem. so please help me. thank you ^_^

<?php
require_once 'connection1.php';
?>
<html>
<link rel="stylesheet" type="text/css" href='https://cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css'/>

<?php

$sql="SELECT * FROM dweetcom_borang . borang_kepuasan";
$result=mysqli_query($conn,$sql);

echo "<table id='example' class='display' cellspacing='1' width='100%'>";
echo "<thead>";
echo "<tr>";
echo "<td>#</td>";
echo "<td>   Nama Anda&Pasangan   </td>";
echo "<td>Soalan 1</td>";
echo "<td>Soalan 2</td>";
echo "<td>Soalan 3</td>";
echo "<td>Soalan 4</td>";
echo "<td>Soalan 5</td>";
echo "<td>Soalan 6</td>";
echo "<td>Soalan 7</td>";
echo "<td>        Nota / Testimoni        </td>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";

if($result === false) {

    }
    else {
        if (mysqli_num_rows($result) > 0) {

                while ($row = mysqli_fetch_assoc($result)) {
                    echo "<tr>";
                    echo "<td><input name= checkbox[] type=checkbox id=checkbox[] value=$row[id]></td>"; 
                    echo "<td>$row[nama]</td>";
                    echo "<td>$row[soalan1]</td>";
                    echo "<td>$row[soalan2]</td>";
                    echo "<td>$row[soalan3]</td>";
                    echo "<td>$row[soalan4]</td>";
                    echo "<td>$row[soalan5]</td>";
                    echo "<td>$row[soalan6]</td>";
                    echo "<td>$row[soalan7]</td>";
                    echo "<td>$row[nota]</td>";
                    echo "</tr>";
                }
            } else {
                echo "0 results";
            }
        }

echo "</tbody>";
echo "</table>";
 echo "<center>";
 echo "<table>";
 echo "<tr>";
 echo "<td>";
     echo "<button style=height:30px width:80px type=submit id=reset name=reset action=POST onClick='reset()'>"; 
     echo "DELETE";
     echo "</button>";
 echo "</td>";
 echo "<td>";
     echo "<button style=height:30px width:80px value=Kembali onClick=location.href='admin1.php'>";
     echo "Kembali";
     echo "</button>";
 echo "</td>";

 echo "<td>";
     echo "<button style=height:30px width:80px value=Log Out onClick=location.href='logout.php'>";
     echo "Log Out";
     echo "</a>";
     echo "</button>";
echo "</center>";
?>

<?php

// Check if delete button active, start this 
if($delete){
for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
$sql = "DELETE FROM $dweetcom_borang WHERE id=$del_id";
$result = mysqli_query($sql);
}

// if successful redirect to delete_multiple.php
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=admin_kepuasan.php\">";
}
}

?>

</html>
<script src='//code.jquery.com/jquery-1.12.4.js'></script>
<script src='https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js'></script>
<script>
$('#example').DataTable();
</script>

Hi!

This variable $dweetcom_borang is not defined in the script and it is used in the delete statement:

$sql = "DELETE FROM $dweetcom_borang WHERE id=$del_id";

I see, however, that in the select statement, at line 9,you are not using a variable, so I wonder if this is the issue. Let us know, bye!

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.