record not getting deleted

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
angelic_devil
Forum Commoner
Posts: 74
Joined: Thu Apr 02, 2009 7:05 am

record not getting deleted

Post by angelic_devil »

i have a listbox with lists which is populated from the database now i want tht when i select a particular record in tht listbox and then click on remove button it shoudl remove tht record from database...but it doesnt it just shows me the msg "genre cud not be deleted and Undefined index: genrename at line 20.

alos i want tht on deletetion the fresh list be populated in the listbox.

plz advice

here's my code

Code: Select all

 
 
<?php
$genrename = 'genrename';
$genrevalue = array();
 
$query_name = "SELECT image_category.genre FROM image_category ";
    $result = mysql_query($query_name);
    confirm_query($result);
        
?>
 
 
<?php
$genre_select = $_POST['genrename'];
//-----------remove genre form database ---------------------
 
if (isset($_POST['remove_genre'])) { 
$query = "DELETE * FROM image_category WHERE image_category.genre LIKE '%$genre_select%'";
$result = mysql_query($query, $connection);
if ($result) {
             $message = " genre has been removed from the list";
         }
         else { $message = " genre could not be removed from the list";}
}
?>
 
 
        <td id="page">
<?php if (!empty($message)) {echo "<p class=\"message\">" . $message . "</p>";} ?>
<form action="genre_remove.php" method="post">
<table>
 
<div style="position: absolute; width: 100px; height: 32px; z-index: 1; left: 225px; top: 5px" id="layer1">
<td><INPUT TYPE = "hidden" VALUE = "" NAME = "genretitle"><br>
<select name="genrename" maxlength="30">
<?php 
        //-----------displays genre from database ---------------------
            while ($record = mysql_fetch_assoc($result)) {
        while (list($genrename, $genrevalue) = each ($record)) {
        echo '<option>'.htmlentities($genrevalue).'</option>';
        
        }
        echo "<BR>";
                
    }   
                
    
?>  
 
 
  </select> </td>
  </div>
<tr>
                    <td colspan="2"><input type="submit" name="remove_genre" value="remove_genre" /></td>
                </tr>
            </table>
 
</form>
</td>
 
 
 
 
</body>
 
Last edited by Benjamin on Sat Apr 25, 2009 4:28 am, edited 1 time in total.
Reason: Changed code type from text to php.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: record not getting deleted

Post by Benjamin »

You don't need the * in the DELETE query.
angelic_devil
Forum Commoner
Posts: 74
Joined: Thu Apr 02, 2009 7:05 am

Re: record not getting deleted

Post by angelic_devil »

its still not deleting
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: record not getting deleted

Post by Benjamin »

What is the query that is being sent to the server? Are you getting any error messages?
Daisy100
Forum Newbie
Posts: 6
Joined: Sat Apr 25, 2009 10:48 am

Re: record not getting deleted

Post by Daisy100 »

Try
$query = "DELETE FROM image_category WHERE image_category.genre LIKE '%".$genre_select."'%'";
(I added the extra double quotes)
May be you should do a print of the query and check whether $genre_select is empty.
angelic_devil
Forum Commoner
Posts: 74
Joined: Thu Apr 02, 2009 7:05 am

Re: record not getting deleted

Post by angelic_devil »

its echoing the correct selection from the listbox so i guess the error is in delete statement cant figure out wats wrong...plz help..

Code: Select all

 
$query = "DELETE * FROM image_category WHERE image_category.genre = $genre_select";
 
echo $genre_select;
 
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: record not getting deleted

Post by Benjamin »

You are missing single quotes around the string in the query, the * doesn't need to be there, and the string also needs to be escaped.

Code: Select all

 
$query = "DELETE FROM image_category WHERE image_category.genre = '" . mysql_real_escape_string($genre_select) . "'";
 
angelic_devil
Forum Commoner
Posts: 74
Joined: Thu Apr 02, 2009 7:05 am

Re: record not getting deleted

Post by angelic_devil »

yes thanx so much its working but its showing me an error
Notice: Undefined index: genrename in D:\wamp\www\php_stockphotos\trials\remove_genre.php on line $genre_select = $_POST['genrename'];
angelic_devil
Forum Commoner
Posts: 74
Joined: Thu Apr 02, 2009 7:05 am

Re: record not getting deleted

Post by angelic_devil »

also once removed i want the list to be populated witht the fresh data after removing the one selected but it shows blank
Post Reply