Problems with database record delete function

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
kraadde
Forum Newbie
Posts: 1
Joined: Fri Jan 12, 2007 5:13 am

Problems with database record delete function

Post by kraadde »

I programmed following code which is supposed to provide the following:
A table is displayed containing filtered records from a MySQL dB. on the right of each record there is a checkbox for the user to select which record has to be deleted. A button on the bottom should start deleting the records and display a fresh table.

I have it donloaded on following [www.playbad.devide.ch/Wunsch_liste.php]. What I am getting is always Error messages and I could not find a solution for the problem:



Notice: Undefined index: eintrag in ....

Warning: implode() [function.implode]: Bad arguments. ...


I tried everything, but I might have overlooked something. Anyone can give me a hint?


kraadde

kraadde@yahoo.com



Code: Select all

<div style="width:98%; height:400px; overflow:auto; border:0px solid #840; margin:1em;"> 

<?php 

echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="POST">'; 


$res_wunsch = mysql_query("SELECT * FROM wunsch_in order by in_time"); 
// ID, w_ID, w_artist, w_title, w_duration, hoerer, dedication, in_time 

/* Anzahl Datensätze ermitteln und ausgeben */ 
$num_wunsch = mysql_num_rows($res_wunsch); 
echo "$num_wunsch Musikwünsche gefunden<br>"; 
echo "<br>"; 


/* Datensätze aus Ergebnis ermitteln, */ 
/* in Array speichern und ausgeben */ 
while ($dsatz_wunsch = mysql_fetch_assoc($res_wunsch)) 
{ 
echo "<table border='0' width='98%' rules='rows' >" 
. "<tr>" 
. "<td col width='5%' bgcolor='#FFFFFF'>" 
. $dsatz_wunsch["w_ID"]. "</td>" 
. "<td col width='15%' bgcolor='#FFFFFF'>" 
. str_replace("\'", "'",$dsatz_wunsch["w_artist"]). "</td>" 
. "<td col width='15%' bgcolor='#FFFFFF'>" 
. str_replace("\'", "'", $dsatz_wunsch["w_title"]) . "</td>" 
. "<td col width='6%' bgcolor='#FFFFFF'>" 

// Umwandeln der Zeitangabe (Songdauer) von ms in minuten 

. msTominsec($dsatz_wunsch["w_duration"]). "</td>" 
. "<td col width='12%' bgcolor='#FFFFFF'>" 
. $dsatz_wunsch["hoerer"]. "</td>" 
. "<td col width='16%' bgcolor='#FFFFFF'>" 
. $dsatz_wunsch["in_time"]. "</td>" 
. "<td col width='24%' bgcolor='#FFFFFF'>" 
. $dsatz_wunsch["dedication"]. "</td>" 
. "<td col width='5%' bgcolor='#FFFFFF'>" 

. "<input type='checkbox' name='eintrag[]' value='" . $dsatz_wunsch['ID'] ."'>" 

. "</tr>" 
. "</table>"; 
} 

echo "<input type= 'submit' name='eintrag' id='send' value='Löschen'>" 


. "</form>"; 


$datensatz_ids = $_POST['eintrag']; // dies ist das array aller markierten einträge 
$query = "DELETE FROM wunsch_in WHERE ID IN(".implode(",", $datensatz_ids) .")"; // so sieht der query zum 

Löschen aus 
?> 

<?php 




?> 


</div>
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

The problem is with your HTML.

Your "eintrag" array of checkboxes is being over-written by your submit button of the same name.

Remove the name from the submit button altogether - it's useless anyway.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

red alert: SQL injection
Post Reply