Hey Monks,

I need your advice and feedback on the following (partial) code. What it does is removing checked values of an html form from a mysql table. Each value is named with an identical value 'id'
# 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();
Is that the way to accomplish deletion of entries in a table from a mysql database?

In reply to Delete multiple values from mysql db.. by kiat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.