Is that the way to accomplish deletion of entries in a table from a mysql database?# sample source from html <form name="samp_db"> Row 1: Megan, Column 2: F, Column 3: 1<input type="checkbox" name="id" + value="1"><br> Row 2: Joseph, Column 2: M, Column 3: 2<input type="checkbox" name="id +" value="2"><br> Row 3: Kyle, Column 2: M, Column 3: 3<input type="checkbox" name="id" +value="3"><br> Row 4: Katie, Column 2: F, Column 3: 4<input type="checkbox" name="id" + value="4"><br> Row 5: Abby, Column 2: F, Column 3: 5<input type="checkbox" name="id" +value="5"><br> <input type="submit" name="submit" value="delete"> </form> # perl code to delete checked values my $dbh = DBI->connect("DBI:${dbtype}:${dbname}", "$dbuser", "$dbpass" +) || die $DBI::errstr; my ($sql, $sth) = ''; # Remove checked values # This is the part of the code that I'm seeking advice on... foreach ($cgi->param('id')) { # name of table is student $sql = "DELETE FROM student WHERE (student_id = $_)"; $sth = $dbh->prepare($sql); $sth->execute() || die $DBI::errstr; } # prints updated table $sql = "SELECT * FROM student"; $sth = $dbh->prepare($sql); $sth->execute() || die $DBI::errstr; # show() is a subroutine that outputs the updated table in html format show();
In reply to Delete multiple values from mysql db.. by kiat
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |