0

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...

5
Contributors
6
Replies
9
Views
4 Years
Discussion Span
Last Post by sagisgirl
0

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.

0

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)

0
$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

0

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.

Edited by diafol

This question has already been answered. 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.