Reputation: 31
I don't find any error in my script in if statement where "submit" is a parameter passed in html form for this script. The error says
"The headers it did return are "syntax error at C:\perlscripts\triallast.pl line 125, near ") {"
I am not able to understand what could be the reason for this error. Can someone help me?
print ("<html><head><title>Test insert questions</title></head>\n");
print ("<body>\n");
<form action = "$ENV{SCRIPT_NAME}" method="GET">
if (defined (param ("submit"))) {
$sql = "INSERT INTO $quiz_table_name ##(qnumber,question,answer,choice1,choice2,choice3,choice4,choice5)##
values(?, ?, ?, ?, ?, ?, ?, ?)";
if (!defined ($sql)) {
&errorPage("Can't insert " . $sql->errstr());
}
$qObj= $dbhandle->prepare($sql)or &errorPage("Can't prepare");
$qObj->execute($formHash{'qnumber'}, $formHash{'question'}, $formHash{'answer'}, $formHash{'choice1'}, $formHash{'choice2'}, $formHash{'choice3'}, $formHash{'choice4'}, $formHash{'choice5'});
$dbhandle->do(sql);
$qObj->finish();
}
Upvotes: 0
Views: 780
Reputation: 69314
The problem is caused by the chunk of HTML that you have put in the middle of your Perl code. That doesn't work.
<form action = "$ENV{SCRIPT_NAME}" method="GET">
Any HTML in your Perl code needs to be in a string which eventually gets printed to STDOUT. So that link should probably be:
print qq(<form action = "$ENV{SCRIPT_NAME}" method="GET">);
Note, I've used qq(...)
here as you want a double-quoted string, but the content of your string already contains double-quote characters. Using qq(...)
is a nice way to handle that without having to escape the embedded double-quotes.
That will fix your problem. But it seems that you also need to work on your understanding of how this stuff works. I'm not sure how you realised that you needed to print the <html>
and <body>
lines, but didn't see the need to print the <form>
line.
And, besides all that, it's 2015. Putting raw HTML into CGI programs has been outdated for fifteen years. Please make your life easier by reading CGI::Alternatives and choosing a more maintainable way to do this.
Upvotes: 2