shopnil shopnil - 1 year ago 45
SQL Question

Delete Button error in php

I have page where there is a delete button to delete a row in a table.but the button is not working.Can any one help me to fix the issue.I am giving my code below .I am new to coding with php.It will be helpful to give me code example. Thanks in advanced.


<td style="border:dotted 1px #999999; text-align:center">
<a href="delete.php?nd_id=<?php echo $row['ND_ID'];?>" style="text-decoration:none; color:#000" title="Delete">
<strong><img src="images/cross-icon.png" width="18" height="18" /></strong></a></td>


$DateTime = gmdate('D d-m-Y H:i:s', strtotime('+6 hours'));
$DateAdd = gmdate('d-M-Y', strtotime('+6 hours'));


$username = $_SESSION['username'];
$usertype = $_SESSION['usertype'];

setcookie("user", "$username", time()+3600);
if($usertype == "admin") {


if($_GET['nd_id']) {
$ND_ID = mysql_escape_String($ND_ID);
$deleteUser = "delete from user_info where nd_id = '$ND_ID'";
if (!mysql_query($deleteUser)) {
die('Error: ' . mysql_error());
else {
$successmassage = "User Row Deleted";
echo $successmassage;


Answer Source

Why you added exit; over here? Your delete query will never work because exit will stop the execution of code after print_r("$ND_ID");

UPDATE: Please go through below points

1) print_r always used to print array and $ND_ID is not array so you can use echo like echo $ND_ID;

2) data type for nd_id column is string or int? if it's an int you dont need to wrap it with quotes like '$ND_ID' in your query you can just write WHERE nd_id = $ND_ID

3) When you clicking delete button, check the url wheather the value of nd_id is being passed or not like delete.php?nd_id= OR delete.php?nd_id=any_value

4) if value is being passed in delete.php, then echo it in php code as I said in 1st point

5) change your code if($_GET['nd_id']) to if(isset($_GET['nd_id'])) as Frayne Konok said