Why are you hard coding each individual option? After you retrieve your opions from the database, you store them in an array, so why not loop like so:
use strict; my @options = ( 'Perfect for me', 'Okay, but my first choice was taken', 'My real name, blame my parents', 'Cowboy Neal', ); for (0..$#options) { print "<tr>\n<td align='left' bgcolor='#8f4141'>\n"; print "<font color='#eabf12' size='2'>\n"; print qq|<input name="in_vote" type="radio" value="option_$_">$opti +ons[$_]</font>\n|; print "</td>\n</tr>\n"; }
This is much better, not only because you do not repeat redundant code, but because you are working on N options, not a finite number, like six. But multiple print statements are icky - learn to avoid them now. One alternative is to let CGI.pm do the hard work for you. Also, where are your opening and closing <table> tags? And why are you exiting at the end of the subroutine?

Lastly, your database schema is, i am sorry to say, not very good at all. At it's very simplest, you only need three tables (not including tables for user info):

Poll
  1. id (primary key)
  2. user_id (foreign key from user table - user who started poll)
  3. description
  4. date_started
  5. date_ended
Option
  1. id (primary key)
  2. poll_id (foreign key to poll table - which poll does this option belong to)
  3. number (what order to place in poll)
  4. description
Vote
  1. user_id (foreign key to user table - who voted on this option)
  2. option_id (foreign key to option table - which option was voted on)
If you wanted to get a list of the options for the poll whose id is 42, you could issue the following query:
select option.description from option inner join poll on option.poll_id = poll.id order by option.number
If you wanted to get the taly of votes from poll 42 ... well, i will leave that as an excercise. >:) Working with properly designed database tables requires a lot of dilligent effort. Maybe you should be working on something a tad bit less challenging, like learning CGI.pm and templating solutions, before you jump right into databases.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to (jeffa) Re: Voting script using MySQL and DBI by jeffa
in thread Voting script using MySQL and DBI by lagrenouille

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.