I have very limited knowledge about server-side development. I am trying to do a project for school. I have to use perl to write a script that will access a table in MySQL. Using XAMPP on windows 7 for server.
The client is just a simple button for now
<html>
<body>
<form method="POST" action="/cgi-bin/perltest.cgi">
<input type="submit" value="Test">
</form>
</body>
</html>
If I use XAMPP's default perltest.cgi which is
#!"C:\xampp\perl\bin\perl.exe"
print "Content-type: text/html\n\n";
print '<html>';
print '<head>';
print '<meta name="author" content="Kay Vogelgesang">';
print '<link href="/xampp/xampp.css" rel="stylesheet" type="text/css">';
print '</head>';
print "<body> <p><h1>GCI with MiniPerl</h1>";
print "CGI with MiniPerl is ready ...</body></html>";
it works fine. The problem starts when I write my own test.cgi to try to use DBI module to connect to my database.
The sample code for the database connection was provided by my teacher.
#!"C:\xampp\perl\bin\perl.exe"
use DBI;
$dbh = DBI->connect('dbi:mysql:perltest','root','')
or die "Connection Error: $DBI::errstr\n";
$sql = "select * from test";
$sth = $dbh->prepare($sql);
$sth->execute
or die "SQL Error: $DBI::errstr\n";
while (@row = $sth->fetchrow_array) {
print "@row\n";
}
Whenever I try to run this, I get the error
Server error!
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script.
If you think this is a server error, please contact the webmaster.
Error 500
127.0.0.1
Apache/2.4.29 (Win32) OpenSSL/1.0.2l PHP/7.1.11
Apache's error log gives me the following message
[Sat Nov 18 00:36:56.126755 2017] [win32:error] [pid 7420:tid 1620] [client 127.0.0.1:50370] AH02102: C:/xampp/cgi-bin/test.cgi is not executable; ensure interpreted scripts have "#!" or "'!" first line, referer: http://127.0.0.1/test.html
[Sat Nov 18 00:36:56.126755 2017] [cgi:error] [pid 7420:tid 1620] (9)Bad file descriptor: [client 127.0.0.1:50370] AH01222: don't know how to spawn child process: C:/xampp/cgi-bin/test.cgi, referer: http://127.0.0.1/test.html
As you can see I have used #!
. I have no idea where I am going wrong.