Been trying to delete a row in mysql like this but its not working. It echoes "failed to delete".
I dont know what is wrong with the code. Any suggestions will be welcomed.
<?php
error_reporting(0);
include("db_config.php");
// array for JSON response
$response = array();
if( isset($_GET['id'] ) ) {
$id=$_GET['id'];
$data=$_GET['data'];
$item=$_GET['item'];
$time=$_GET['time'];
$result = mysql_query("delete from myorder where id='$id' ");
$row_count = mysql_affected_rows();
if($row_count>0){
$response["success"] = 1;
$response["message"] = "Deleted Sucessfully.";
}
else{
$response["success"] = 0;
$response["message"] = "Failed To Delete";
}
// echoing JSON response
echo json_encode($response);
}
?>
My table structure:
CREATE TABLE `myorder` (
`id` int(100) NOT NULL AUTO_INCREMENT,
`data` varchar(20) NOT NULL,
`item` varchar(255) DEFAULT NULL,
`time` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=27 ;
And my primary data is:
INSERT INTO `myorder` VALUES(23, '500MB', 'safaricom \nsteve\n0715611306', '11:32 PM 26 Aug, 2015 ');
INSERT INTO `myorder` VALUES(24, '4GB', 'safaricom \nsteve\n0715611306', '00:30 AM 27 Aug, 2015 ');
INSERT INTO `myorder` VALUES(25, '9\nGB', 'airtel \nsteve\n0715611306', '00:31 AM 27 Aug, 2015 ');
INSERT INTO `myorder` VALUES(26, '9\nGB', 'airtel \nsteve\n0715611306', '00:31 AM 27 Aug, 2015 ');