delete from mysql ?

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
Gemster
Forum Newbie
Posts: 13
Joined: Thu Jul 29, 2010 10:38 am

delete from mysql ?

Post by Gemster »

Hi,

Ok i have no idea on how to do :/

Basically i have a script that gets info from a mysql database and prints in to a page. I have added checkbox infront of the data and a delete button

Code: Select all

<?php 
 while($bip = mysql_fetch_array( $data )) 
 {
?>
<input name="bcheck" type="checkbox" value="<?php echo $IP['id']; ?>" id="bcheck">
<?php
 Print "<b>Ip:</b> ".$bip['ip'] . " ".$bip['ipnote'] . " <br>"; 
}
?>
<div>
<br>
<input name="bd" type="submit" id="bd" value="Delete">
Mysql database name is "IP"

Format in the database is this:

id ip ipnote
1 1.1.1.1 test
2 2.2.2.2 test
3 3.3.3.3 test
4 4.4.4.4 test

What i need is for it to delete the selected lines from the database, maybe from the id

Thanks
Gemster
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: delete from mysql ?

Post by Celauran »

Change bcheck to bcheck[]. Once the form has been submitted, you can then loop through the checked values of $_POST['bcheck'] to create your DELETE FROM query.
Gemster
Forum Newbie
Posts: 13
Joined: Thu Jul 29, 2010 10:38 am

Re: delete from mysql ?

Post by Gemster »

Ok, im a complete noob at this.

Im guessing that i need it to get the id of the selected box or somet then delete that ip from mysql but i have no idea on how to do this :/

Any help would be great, or examples that i can test and somehow crete this.

Or would it be easyer to just add the work Delete after the ip and ipnote, then hot Delete and this deletes that line from mysql ?

Thanks
Gemster

EDIT: nvm i found a good tut for this http://www.phpeasystep.com/mysql/8.html :D
Post Reply