Hi guys...

I have a trouble with my delete page.. here are my codes..

<?php
include("enter.php");
$dbjpu_jenis_jentera=$_GET['jpu_jenis_jentera'];
//if(isset($_GET['bil'])){ $dbstaf_bil = $_GET['bil']; }
$sql="DELETE FROM jpuma_jkkp2013 WHERE jpu_jenis_jentera='".$dbjpu_jenis_jentera."'";
$result=@mysql_query($sql);

if($result){
echo "<center>Please wait a few second.<br>The data was deleted from database...<meta http-equiv='refresh' content='3;url=jpuma_jkkp2013.php'>";

//echo "<p>";
//echo "";
}

else {
echo "ERROR";
}
?> 

<?php
include("exit.php");
?>

the problem is after i click the "delete button", all the data in my tables are all gone..it deleted all my data..why is that problem occur...can someone help me...

can you give the db table structure of the table involved.

Check the query. Insert this code right after line 5:

die($sql);

It is a simple debugging technique. It will display the query and you can inspect it and test it in phpmyadmin. You can also post it here.

oh sure..here..

CREATE TABLE IF NOT EXISTS jpuma_jkkp2013 (
jpu_id int(25) NOT NULL,
jpu_jenis_jentera varchar(25) NOT NULL,
jpu_no_pendaftaran int(50) DEFAULT NULL,
jpu_tarikhtamat_lesen date DEFAULT NULL,
jpu_tarikh_diperiksa date DEFAULT NULL,
jpu_lokasi varchar(10) DEFAULT NULL,
jpu_tuntutan_jkkp varchar(25) DEFAULT NULL,
jpu_rujukan varchar(25) DEFAULT NULL,
PRIMARY KEY (jpu_id)

$dbjpu_jenis_jentera=$_GET['jpu_jenis_jentera'];
//if(isset($_GET['bil'])){ $dbstaf_bil = $_GET['bil']; }
$sql="DELETE FROM jpuma_jkkp2013 WHERE jpu_jenis_jentera='".$dbjpu_jenis_jentera."'";
echo $dbjpu_jenis_jentera. " ".$sql;

check the out put of both varables

Member Avatar for diafol

I'd suggest something like this:

if(isset($_GET['jpu_jenis_jentera'])){
    $dbjpu_jenis_jentera= mysql_real_escape_string($_GET['jpu_jenis_jentera']);
    $sql = "DELETE FROM jpuma_jkkp2013 WHERE jpu_jenis_jentera='$jpu_jenis_jentera'";
    $result = mysql_query($sql) or die(mysql_error());
//...rest of code...
}

I think your error was $dbjpu_jenis_jentera in the query instead of $jpu_jenis_jentera

BTW - you may wish to shorten the url querystring key as long names can lead to mistakes when writing processing code. Not impt thought.

ok thanks...it worked now...thanks a lot... :)

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.