Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 135,914 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 2,589 people online right now. Registration is fast and FREE... Join Now!




delete row if checked (checkbox)

 
Reply to this topicStart new topic

delete row if checked (checkbox)

daniela99
23 May, 2008 - 04:43 AM
Post #1

New D.I.C Head
*

Joined: 15 May, 2008
Posts: 1

Hi everyone,
I'm trying to delete a row from a database if it's checked (checkbox). Why doesn't it work like this?
(the file is bookmark_n5.php)
<code>
<form id="deleting" action="bookmark_n5.php" method="post">
<input type="hidden" name="deleting" value="aap" />
<ol>
<?php
while($row = mysql_fetch_array($result))
{
$seq = $row['seq'];
echo('<li><p>');
echo('<input type="checkbox" name="'.'deleteme'.$seq.'" value="" >');
echo($seq);
echo(' - <a href=" ' . $row['url'].' " >');
echo($row['desc']);
echo('</a></p></li>');
}
?>
</ol>
<?php
if(isset($_POST["deleteme"]))
{
// checked
$query = "DELETE * FROM bookmark WHERE seq = 'TRUE' ";
$result = mysql_query($query);
}
else
{
// unchecked
}
?>
<input type="submit" value="delete checked">
</form>
</code>
thanks for any help,
Daniela
User is offlineProfile CardPM
+Quote Post

joeyadms
RE: Delete Row If Checked (checkbox)
23 May, 2008 - 05:12 AM
Post #2

D.I.C Head
Group Icon

Joined: 4 May, 2008
Posts: 145



Thanked: 6 times
Dream Kudos: 600
Expert In: PHP, Web Security

My Contributions
There are a number of things with this that should be looked at. First though, lets look at your query. What is "seq" supposed to be? So no matter what row you check, it deletes all from bookmark where seq=True.

Now echo is not a function, it's a construct, so lets start using echo like this echo "vars";

And the naming convention on the check box, thats your main problem I believe you want something like this?
CODE

echo "<input type='checkbox' name='deleteme' value='".$seq."'/>


But I imagine what you want to do is delete each row that is checked. Assuming $seq is equal to an ID column, then use the above checkbox input except replace deleteme with deleteme[]

Then on post just cycle through the array deleting records that need be , or for better performance wait till you've recursed through the array and construct and sanitize, one query to delete all the rows.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 07:55AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month