Page 1 of 1

delete from mysql ?

Posted: Fri May 13, 2011 7:52 am
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

Re: delete from mysql ?

Posted: Fri May 13, 2011 9:24 am
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.

Re: delete from mysql ?

Posted: Fri May 13, 2011 2:24 pm
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