Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9002833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:37:26+00:00 2026-06-16T00:37:26+00:00

This is my first time programming with both perl and databases, I’m having some

  • 0

This is my first time programming with both perl and databases, I’m having some issue determining how exactly to write a perl script that will input the results from an html form into a mysql database.

This particular snippet is what is causing me issue:

    # CONFIG VARIABLES
    $platform = "mysql";
    $database = "*****";
    $host = "localhost";
    $port = "3306";
    $user = "*****";
    $pw = "*****";

    # DATA SOURCE NAME
    $dsn = "dbi:$platform:$database:$host:$port";

    # PERL DBI CONNECT
    $connect = DBI->connect($dsn, $user, $pw);

    # PREPARE THE QUERY
    $query = "INSERT INTO result (name, console, character, series, bday, steam) VALUES (fname, favConsole, fCharacter, favSeries, birthday, steamAcc)";
    $query_handle = $connect->prepare($query);

    # EXECUTE THE QUERY
    #$query_handle->execute();

I replaced the database name, username and password with asterisks but the real code has the true values.

I’m not certain why the connect and execute lines are giving me issue.

Also where exactly would I put the prompt so the information is written once the user hits the submit button? I tried adding execute as the form action but that didn’t work.

This is my work so far:

    #!/usr/bin/perl

    use CGI qw( :standard );
    use DBI;
    use DBD::mysql;

    # CONFIG VARIABLES
    $platform = "mysql";
    $database = "*****";
    $host = "localhost";
    $port = "3306";
    $user = "*****";
    $pw = "*****";

    # DATA SOURCE NAME
    $dsn = "dbi:$platform:$database:$host:$port";

    # PERL DBI CONNECT
    $connect = DBI->connect($dsn, $user, $pw);

    # PREPARE THE QUERY
    $query = "INSERT INTO result (name, console, character, series, bday, steam) VALUES (fname, favConsole, fCharacter, favSeries, birthday, steamAcc)";
    $query_handle = $connect->prepare($query);

    # EXECUTE THE QUERY
    #$query_handle->execute();

    $dtd =
    "-//W3C//DTD XHTML 1.0 Transitional//EN\"
       \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";

    print( header() );

    print( start_html( { dtd => $dtd,
      title => "~Video Game Survey~" } 
      #style=>{"background-image:url(/images/blue_line_background.jpg) ";
      #}
      ) );
    #print( " <body style="background-image:url(/images/blue_line_background.jpg)">\n " );


    print( "<body>\n" );
    print(     "<div style = \"font-size: 14pt; font-weight: bold\">\n" );
    print(      "Please let us know a bit more about yourself.\n" );
    print(     "</div>\n" );
    print( "</body>\n" );

    print( "<br />\n " );

    #Start of the form.
    print( "<form method = \"post\" > \n" );

    #First question, asking the visitor's name.  Name will be stored in the database         but not displayed on the
    #survey results.
    print( "<p>\n" );
    print(      "First of all, what is your name?\n" );
    print(      "<input type = \"text\" name = \"fname\" placeholder = \"John Doe\" required />\n" );
    print( "</p>\n" );

    print( "<br /><br />\n" );

    #Second question, type dropdown list.
    print( "<img src = \"/images/favConsole.png\" />\n");
    print( "<p>\n" );
    print(      "Gaming comes in all sorts of shapes and sizes.  What is your favorite console?\n" );
    print( "</p>\n" );
    print( "<dd>\n" );
    print(      "<input type = \"text\" name = \"favConsole\" placeholder = \"Select a console\"
                   list = \"consoles\" required/>\n" );
    print(              "<datalist id = \"consoles\">\n" );
    print(                  "<option value= \"PC\">\n" );
    print(                  "<option value= \"Playstation 3\">\n" );
    print(                  "<option value= \"Xbox 360\">\n" );
    print(                  "<option value= \"Wii\">\n" );
    print(              "</datalist>\n" );
    print( "</dd>\n");

    print( "<br /><br />\n" );

    #Third question, type radio.  Default value: Mario
    print( "<img src = \"/images/favCharacter.png\" />\n" );
    print( "<p>\n" );
    print(      "Out of the following list, who is your favorite video game character?\n" );
    print( "</p>\n" );
    print(      "<dd><input name = \"fCharacter\" type = \"radio\" value = \"Mario\" checked><label>Mario</label></dd>\n" ); 
    print(      "<dd><input name = \"fCharacter\" type = \"radio\" value = \"Sephiroth\" ><label>Sephiroth</label></dd>\n" );
    print(      "<dd><input name = \"fCharacter\" type = \"radio\" value = \"Sonic\" ><label>Sonic</label></dd>\n" );
    print(      "<dd><input name = \"fCharacter\" type = \"radio\" value = \"Thrall\" ><label>Thrall</label></dd>\n" );
    print(      "<dd><input name = \"fCharacter\" type = \"radio\" value = \"Pacman\" ><label>Pacman</label></dd>\n" );
    print(      "<dd><input name = \"fCharacter\" type = \"radio\" value = \"Cloud\" ><label>Cloud</label></dd>\n" );
    print(      "<dd><input name = \"fCharacter\" type = \"radio\" value = \"Sylvanas\" ><label>Sylvanas</label></dd>\n ");
    print(      "<dd><input name = \"fCharacter\" type = \"radio\" value = \"Kerrigan\" ><label>Kerrigan</label></dd>\n ");
    print( "</dd>\n" );

    print( "<br /><br />\n" );

    #Fourth question, type dropdown.  Required.
    #Dropdown options will not appear unless the window is maximized in terms of height.
    print( "<img src = \"/images/favSeries.png\" />\n" );
    print( "<p>\n" );
    print(      "Which of the following series is your favorite?\n" );
    print( "</p>\n" );
    print(      "<input type = \"text\" name = \"favSeries\" placeholder = \"Select a series\"
                   list = \"series\" required/>\n" );
    print(              "<datalist id = \"series\">\n" );
    print(                  "<option value= \"Legend of Zelda\">\n" );
    print(                  "<option value= \"Halo\">\n" );
    print(                  "<option value= \"Bioshock\">\n" );
    print(                  "<option value= \"Resident Evil\">\n" );
    print(                  "<option value= \"Mario Party\">\n" );
    print(                  "<option value= \"Angry Birds\">\n" );
    print(                  "<option value= \"The Sims\">\n" );
    print(                  "<option value= \"Mass Effect\">\n" );
    print(                  "<option value= \"Half-Life\">\n" );
    print(                  "<option value= \"Warcraft\">\n" );
    print(                  "<option value= \"Starcraft\">\n" );
    print(                  "<option value= \"Borderlands\">\n" );
    print(              "</datalist>\n" );

    print( "<br /><br />\n" );

    #Fifth question, type date.  No default value, but still required.
    print( "<img src = \"/images/bday.png\" />\n" );
    print( "<p>\n" );
    print(      "What is your cake day?\n" );
    print( "</p>\n" );
    print(      "<input type = \"date\" name = \"birthday\" required />(yyyy-mm-dd)\n" );

    print( "<br /><br />\n" );

    #Sixth question, type radio.  Default value: no.
    print( "<p>\n" );
    print(      "Last but not least, do you have a Steam account?\n" );
    print(      "<input name = \"steamAcc\" type = \"radio\" value = \"Y\" >        <label>Yes</label>\n" );
    print(      "<input name = \"steamAcc\" type = \"radio\" value = \"N\" checked>        <label>No</label>\n" );
    print( "</p>\n" );

    print( "<p>\n" );
    print(      "<input type = \"submit\" value = \"Submit\" />\n" );
    print(      "<input type = \"reset\" value = \"Clear\" /></p>\n" );
    print( "</p>\n" );

    #End of the form
    print( "</form>\n" );

    print( end_html() );
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:37:26+00:00Added an answer on June 16, 2026 at 12:37 am

    A few things to start off with:

    1. Add these lines to the top of your script for safety in your code.

      use strict;
      use warnings;
      
    2. The above step means you will need to declare ALL of your variables with my, e.g.

      my $dsn = ...
      
    3. Tell DBI to throw an error if anything is wrong with the connection or execution (it doesn’t do this by default). From the error messages you can get some more clues to figure out what is happening.

      my $dbh = DBI->connect($dsn, $user, $pw, {RaiseError => 1});
      
    4. Use placeholders for your SQL (which prevents SQL injection, and also adds quotes your insert values in the SQL automatically)

      my $query = 'insert into (name, console) values (?, ?)';
      my $sth = $connect->prepare($query);
      $sth->execute('fname', 'favConsole');
      # this is equivalent to:
      # "insert into (name, console) values ('fname', 'favConsole')"
      
    5. Your values need to be pulled from the CGI params (which I’m guessing you’re not up to that stage just yet).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been learning sqlite3 programming in C++ for the first time and this error
This is my first time Qt programming. I am to make an address book
I'm relatively experienced with Object oriented programming, but this is my first time ever
This is my first time do programming; i have a project that requires netwok
this is my first time using Eclipse, and my first time programming in a
Full disclosure: This is my first time doing any significant programming in C, and
This is my first time ever touching any sort of client sided web programming
This is my first time working with a WPF datagrid. From what I understand
this is my first time asking a question here. I tried to be well
This is my first time that I use WCF and Android. So, sorry for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.