Page 1 of 1

record not getting deleted

Posted: Sat Apr 25, 2009 4:15 am
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>
 

Re: record not getting deleted

Posted: Sat Apr 25, 2009 4:29 am
by Benjamin
You don't need the * in the DELETE query.

Re: record not getting deleted

Posted: Sat Apr 25, 2009 4:34 am
by angelic_devil
its still not deleting

Re: record not getting deleted

Posted: Sat Apr 25, 2009 4:41 am
by Benjamin
What is the query that is being sent to the server? Are you getting any error messages?

Re: record not getting deleted

Posted: Sat Apr 25, 2009 11:12 am
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.

Re: record not getting deleted

Posted: Sat Apr 25, 2009 12:46 pm
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;
 

Re: record not getting deleted

Posted: Sat Apr 25, 2009 12:49 pm
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) . "'";
 

Re: record not getting deleted

Posted: Sat Apr 25, 2009 1:29 pm
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'];

Re: record not getting deleted

Posted: Sat Apr 25, 2009 1:30 pm
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