Click here to Skip to main content
15,886,666 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a simple MySQL statement that should delete the selected row. I have an update query that works well. It inserts but doesn’t delete.

I am not an expert but the query is simple and easy to read. I do not understand why it is not deleting the data.

Form
PHP
$Band_id = (int)$_GET['id'];
$result = mysql_query("SELECT * FROM bands ");

echo "<table border = '1'>
<h4>Edit or Deleat Show:</h4>

<tr>
	<th>Show No</th>
	<th>Band Name</th>
	<th>Venue</th>
	<th>Category</th>
	<th>Stock</th>
	<th>Edit Show</th>
	<th>Delete Show</th>
</tr>";

while($row = mysql_fetch_array($result))
    {
        echo "<td>" .$row['Band_id']. "</td>";
        echo "<td>" .$row['Name']. "</td>";
        echo "<td>" .$row['Venue']. "</td>";
        echo "<td>" .$row['Category']. "</td>";
        echo "<td>" .$row['Stock']. "</td>";
        echo " <input name=\"id\" type=\"hidden\" value=\"". $row["Band_id"] ."\" >";
        echo ("<td><a href=\"editband.php?id=$row[Band_id]\"><button>Edit Details</button></a></td>");
        echo ("<td><a href=\"delete.php?id=$row[Band_id]\"><button>Deleat Show</button></a></td></tr>");
    }
echo "</table>";


delete.php
PHP
require 'core/init.php';

$Band_id = (int)$_POST['id'];

$result = mysql_query ("DELETE  FROM bands WHERE Band_id='$Band_id'");

 echo mysql_error();
//header("location:admin.php");


What I have tried:

Refer delete.php
Posted
Updated 24-Feb-17 6:59am
v2
Comments
gettgotcha 21-Jan-14 12:56pm    
Not sure I think there shouldn't be single quotes in the where condition of the delete statment (remove the single quotes Band_id = $Band_id and try it).
Ben Oats 21-Jan-14 13:00pm    
Ok, thanks for the advice il give it a go
Ben Oats 21-Jan-14 13:04pm    
Tried, has not worked. thank you anyway.
Krunal Rohit 21-Jan-14 12:58pm    
try this:
$result = mysql_query ("DELETE FROM bands WHERE Band_id=" . $Band_id);
Ben Oats 21-Jan-14 13:02pm    
Thanks for advice, have tried and has not worked

Solved
changed post to get ...

PHP
require 'core/init.php';
$Band_id = (int)$_GET['id'];	

$result = mysql_query("DELETE FROM bands WHERE Band_id = $Band_id");

echo "DELETE FROM bands WHERE Band_id = $Band_id"

//header("location:admin.php");

<pre>
 
Share this answer
 
v2
Comments
navjot singh 29-Apr-17 9:05am    
thankyou
try this...
<?php

    require('connection.php');
    $deleteid = $_GET['id'];
    mysql_query("DELETE FORM typing WHERE id='$deleteid'");
    header("location: testing.php");
?><
/pre>


here connecion.php is connectivity file and testing.php is index file as yours
 
Share this answer
 
Comments
[no name] 23-Feb-17 11:59am    
Asked and answered THREE years ago.
navjot singh 29-Apr-17 9:05am    
thankyou

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900