Hi,
I'm a Perl program in Windows 7 32-bit using ActivePerl.
I have created a registration form using HTML and saved this file as Details.html

<!DOCTYPE html> <html> <body> <form name="myform" METHOD="POST" ACTION="D:\Application\perl\cgi-bin\app.pl" onsubmit= "return validation_form()"> <p> <label for="employee name">Employee Name</label> <input type="text" id="employee name" name="employee name" /><br> </p> <p> <label for="password">Password </label> <input type="password" id="password" name="password"/> <div id="errpw"> </div> </p> <p> <label for="dob">DOB </label> <input type="date" id="dob" name="dob"  /> </p> <p> <label for="Gender">Gender</label> <input type="radio" id="gender" name="gender" value="male" /> Male
                <input type="radio" id="gender" name="gender" value="female"/> Female
                <input type="radio" id="gender" name="gender" value="other"/> Other
            </p> <p> <label for="phone number">Phone number</label> <input type="tel" id="Phonenumber" name="Phonenumber"/> </p> <p> <label for="emailid">EmailId</label> <input type="email" id="emailid" name="emailid"/> </p> <p> <label for="ProcessName">Process Name</label> <input type="text" id="ProcessName" name="ProcessName"/> </p> <p> <label for="skillset">Skill Set</label> <input type="text" id="skillset" name="skillset"/> </p> <p> <label for="Designation">Designation</label> <input type="text" id="designation" name="designation"/> </p> <p> <label for="doj">DOJ</label> <input type="date" id="doj" name="doj"/> </p> <p>
                Total Experience
                <select name="number" > <option value="" selected>-</option><option value="0">0</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option> <option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option><option value="11">11</option> <option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option> <option value="18">18</option><option value="19">19</option><option value="20">20</option><option value="21">21</option><option value="22">22</option><option value="23">23</option> <option value="24">24</option><option value="25">25</option><option value="26">26</option><option value="27">27</option><option value="28">28</option><option value="29">29</option> <option value="30">30</option><option value="31">31</option><option value="32">32</option><option value="33">33</option><option value="34">34</option><option value="35">35</option> <option value="35">35</option><option value="36">36</option><option value="37">37</option><option value="38">38</option><option value="39">39</option><option value="40">40</option> <option value="41">41</option><option value="42">42</option><option value="43">43</option><option value="44">44</option><option value="45">45</option><option value="46">46</option> <option value="47">47</option><option value="48">48</option><option value="49">49</option><option value="50">50</option> </select> </p> <p> <button type="submit">Submit</button> </p> </form> </body> </html>

After clicking Submit button, I have to read the values and also to do password,emailid,& phonenumber validations using Perl script with CGI module.I saved this file as app.pl

#!/usr/bin/perl
print "Content-type: text/html\n\n";
use strict;
use warnings;
use CGI qw(:standard);
$|=1;
my $form = CGI->new;
print $form->header ( );
print "CONTENT_LENGTH = $ENV{'CONTENT_LENGTH'}\n";
if ( $ENV{'REQUEST_METHOD'} eq "POST" ) 
{
    read(STDIN,$form, $ENV{'CONTENT_LENGTH'}); 
}
else 
{
    print "\n At least fill something! I cannot work with empty strings";
    exit;
}

foreach my $pair (split('&', $form))
{        
    if ($pair =~ /(.*)=(.*)/)
    {  
    (my $key,my $value) = ($1,$2);    
    $value =~ s/\+/ /g;  
    $value =~ s/%(..)/pack('c',hex($1))/eg;
    my $inputs{$key} = $value;   
    } 
} 
if ($query->$form('submit'))
{
  process_form ();
}
else
{
  display_form ();
}

sub process_form
{
  if (validate_form())
  {
    print <<END_HTML;
    <html><head><title>Thank You</title></head> <body>
    Thank you - your form was submitted correctly!
    </body></html>
END_HTML
  }
}
sub validate_form{
    my $error="";
    my $password = $inputs{"password"};
    if ($password =~ /^[\w\d@#\$%`~!^&*()_\-+={}[\]|\\'";:\/?.><,]{8}$/ && $error=="") {
        print "Please enter the correct password";
    }
    my $Phonenumber = $inputs{"Phonenumber"};
    @ph=split('',$Phonenumber);
    my $size=@ph;
    if($size==11 &&$error==""){
        if($Phonenumber=!/^[6-9]+\d/)
        {
            $error=("Please enter valid phone number");
        }
    }
    my $emailid = $inputs{"emailid"};
    if($emailid=!/([a-zA-Z]+)(\d+)@([a-zA-Z]+)\.(com|net|org)/ && $error=="")
    {
        $error=("Please enter the valid EmailId");
    }
}

Here the main problem is while running the app.pl file from the command promt, the HTML file is not directly opening in the browser and after submitting ,the values has to save in MySQL database.Please help me with this code.

Thanks in Advance.

Dani AI

Generated

Brief diagnosis and where this usually breaks

The root cause is that a browser will not execute a Perl CGI just because you run the .pl from the command prompt or point a form action at a Windows file path. A CGI program must be invoked through an HTTP server (for example the server’s cgi-bin) — opening Details.html with file:/// or submitting to D:\...app.pl won’t run the script on the server. ’s remark about Chrome pop-up blocking is useful only if something in your workflow tries to spawn a new browser window; it does not address the core issue here.

Practical, minimal fixes to get your form working

  • Put the Perl script where your web server will execute it (the server’s cgi-bin or a directory configured for CGI) and change the form action to an HTTP URL or path the server serves (for example http://localhost/cgi-bin/app.pl or /cgi-bin/app.pl).
  • Use forward-slash URL form names (no backslashes) and avoid spaces in name/id attributes (use employee_name not employee name).
  • Test with a very small CGI that only prints a header and “OK” to confirm the server runs CGIs, then progress to your full script.

Code-level bugs to fix (clear, common mistakes)

  • Don’t print the HTTP header twice. Use one method (for example print $q->header), not both a manual Content-type: line and the CGI header helper.
  • Don’t reuse the same scalar for the CGI object and raw POST body; use distinct variables ($q for the CGI object). If you use CGI.pm, prefer $q->param('field') instead of manually reading STDIN.
  • Fix the hash/variable declarations (my %inputs; not my $inputs{$key}) and use the correct operators (=~/!~ for regex, eq/ne for string compare).
  • For database storage, use DBI with prepared statements and placeholders to avoid SQL injection.

Debugging checklist

Enable use strict/use warnings (you already have them), check the web server error log for runtime errors, confirm the server’s CGI settings and that the script is executable, and verify form field names and encodings. Once CGI invocation works, switch to CGI->param and then add DBI code.

Let's say your code is 100% valid, what are you doing about say Chrome and pop-up settings?
tells us that Chrome (and most other browsers) block sites from starting anther instance and automatically showing up on your screen.

Just another thing to consider.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.