LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   HTML Form problem (https://www.linuxquestions.org/questions/linux-newbie-8/html-form-problem-4175482747/)

zak100 10-30-2013 05:45 AM

HTML Form problem
 
Hi,
I have stored my HTML form in cgi-bin directory but its giving me error:
Quote:


Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, root@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.
Apache/2.2.10 (Fedora) Server at localhost Port 80
My HTML code is:
Code:

[root@HP-UX616K cgi-bin]# cat login.html

<HTML>
<HEAD>
<TITLE> LOGIN Page</TITLE>
</HEAD>

<BODY>
<form method="post" action="login.pl">

<TABLE BORDER ="0">
<TR>

<TD> User Name </TD>
<TD>
<input type = "text" name = "username" value="">
</TD>
</TR>
<TR>
<TD>Password</TD>
<TD>
<input type="text" name="password" value=""></TD>
</TR>
<TR>
<TD COLSPAN="2" ALIGN="RIGHT">
<input type="submit" name="submit" value="login">

</TD></TR></TABLE></FORM></BODY></HTML>

[root@HP-UX616K cgi-bin]#

My perl code is:

Code:

[root@HP-UX616K cgi-bin]# cat login.pl

#!/usr/bin/perl
use DBI;
use CGI;
$cgi=new CGI;
$dbh=DBI->connect("dbi:mysql:PerlTest",'root','')or die "unable to connect: $DBI::errstr\n";
$username=$cgi->param('username')||'';

$password=$cgi->param('password')||'';

$submit=$cgi->param('submit')||'';

$sth=$dbh->prepare("select username,password from user where username='$username' and password='$password'");

$sth->execute();
$found=0;
while($row=$sth->fetchrow_hashref)
{
$found=1;
}

if($found)
{
print "<<HTML;
<html>
<body>
<h1>Welcome</h1>
</body>
</html>
HTML";

}

Its executing my perl code:
Quote:

[root@HP-UX616K cgi-bin]# ./login.pl

[root@HP-UX616K cgi-bin]#
I dont know what is the default place for storing html code. I have stored it in the cgi-bin directory. I got this inofrmation from some other forum that it is not the proper place for HTML.
Kindly guide me with this problem. I have not made any changes in my httpd.conf file. I am using default setup.

Zulfi.

Mousepad123 10-31-2013 12:22 AM

Please check your perl syntax with the following code:

Code:

perl -c login.pl

zak100 11-01-2013 02:13 AM

Hi,
I have made changes in my code. Now my perl code is:
Code:

[guest@HP-UX646UU ~]$ ./test.pl
Can't find string terminator "" anywhere before EOF at ./test.pl line 18.
[guest@HP-UX646UU ~]$ cat test.pl
#!/usr/bin/perl
use DBI;
use CGI;
@cgi=new CGI;
##create table
$dbh=DBI->connect("dbi:mysql:testDB",'root','') or die"unable $DBI::errstr/n";
$password=$cgi-> param('password')||'';
$testname=$cgi-> param('testname')||'';
$submit=$cgi-> param('submit')||'';
$sth=$dbh-> prepare("Select testname,password from test where testname='$testname' and password='$pasword'");
$sth-> execute();
$found=0;
while($row=$sth->fetchrow_hashref)
{$found=1;}
if($found)
{
print "Content-type: text/html\n\n";
print << HTML;
<html>
<head>
<title>test page </title></head>
<body>
<h1> A Simple Perl CGI </h1>
<P> Hello World </P>
</body> </html>
HTML }
exit;                                                                                     
[guest@HP-UX646UU ~]$

I am getting following error:
Quote:

[guest@HP-UX646UU ~]$ ./test.pl
Can't find string terminator "" anywhere before EOF at ./test.pl line 18.
[guest@HP-UX646UU ~]$ cat test.pl


Kindly guide me.

Also tell me where the log files of Apache are stored?

Zulfi.

PeterSullivan 11-01-2013 05:30 AM

Quote:

Originally Posted by Mousepad123 (Post 5055668)
Please check your perl syntax with the following code:

Code:

perl -c login.pl

Hi I was also the same error, and I have use your code and now its working fine. thanks for help

zak100 11-01-2013 11:27 PM

Hi,

I am still getting the same error:

Code:

[guest@HP-UX646UU ~]$ perl -c test.pl
Can't find string terminator "HTML" anywhere before EOF at test.pl line 18.
[guest@HP-UX646UU ~]$ !v
vi test.pl
[guest@HP-UX646UU ~]$ cat test.pl
#!/usr/bin/perl
use DBI;
use CGI;
@cgi=new CGI;
##create table
$dbh=DBI->connect("dbi:mysql:testDB",'root','') or die "unable $DBI::errstr\n\n";
$password=$cgi-> param('password')  || '';
$testname=$cgi-> param('testname') || '';
$submit=$cgi-> param('submit')  || '';
$sth=$dbh-> prepare("Select testname,password from test where testname='$testname' and password='$pasword'");
$sth-> execute();
$found=0;
while($row=$sth->fetchrow_hashref)
{$found=1;}
if($found)
{
print "Content-type: text/html\n\n";
print <<HTML;
<html>
<head>
<title>test page </title></head>
<body>
<h1> A Simple Perl CGI </h1>
<P> Hello World </P>
</body> </html>
HTML }
exit;                                                                                     
[guest@HP-UX646UU ~]$

Somebody plz guide me.

Zulfi.

jmc1987 11-02-2013 01:16 AM

Quote:

Originally Posted by zak100 (Post 5056907)
Hi,

I am still getting the same error:

Code:

[guest@HP-UX646UU ~]$ perl -c test.pl
Can't find string terminator "HTML" anywhere before EOF at test.pl line 18.
[guest@HP-UX646UU ~]$ !v
vi test.pl
[guest@HP-UX646UU ~]$ cat test.pl
#!/usr/bin/perl
use DBI;
use CGI;
@cgi=new CGI;
##create table
$dbh=DBI->connect("dbi:mysql:testDB",'root','') or die "unable $DBI::errstr\n\n";
$password=$cgi-> param('password')  || '';
$testname=$cgi-> param('testname') || '';
$submit=$cgi-> param('submit')  || '';
$sth=$dbh-> prepare("Select testname,password from test where testname='$testname' and password='$pasword'");
$sth-> execute();
$found=0;
while($row=$sth->fetchrow_hashref)
{$found=1;}
if($found)
{
print "Content-type: text/html\n\n";
print <<HTML;
<html>
<head>
<title>test page </title></head>
<body>
<h1> A Simple Perl CGI </h1>
<P> Hello World </P>
</body> </html>
HTML }
exit;                                                                                     
[guest@HP-UX646UU ~]$

Somebody plz guide me.

Zulfi.


Wrap your tags using php so it color coats and makes it easier to read, also indention helps out to.

Also you need
PHP Code:

#!/usr/bin/perl

# add these and declare your variables.  Its good general practice.
use warnings;
use 
strict

Make sure you have no whitespace in front of your terminator

Soon as I finish updating my system if somebody else hasn't replied, I'll try to run the code and fix it.

jmc1987 11-02-2013 02:09 AM

Okay found your problem. It should look like this

PHP Code:

print <<HTML;
<
html>
<
head>
<
title>test page </title></head>
<
body>
<
h1A Simple Perl CGI </h1>
<
PHello World </P>
</
body> </html>
HTML


the HTML needs to be on a line by itself.

zak100 11-02-2013 04:17 AM

Hi,
Thanks for your help.
Quote:

the HTML needs to be on a line by itself.
You mean the
HTML
word should be the only word on that line.
My perl code is now:

Code:

[root@HP-UX646UU cgi-bin]# ls
act2.pl  bisma.pl  cg11.pl  code.pl  first1.pl  first.pl  hello.pl  test.pl
[root@HP-UX646UU cgi-bin]# ./test.pl
Content-type: text/html

<html>
<head>
<title>test page </title></head>
<body>
<h1> A Simple Perl CGI </h1>
<P> Hello World </P>
</body> </html>


[root@HP-UX646UU cgi-bin]# cat test.pl
#!/usr/bin/perl
use DBI;
use CGI;
$cgi=new CGI;
##create table
$dbh=DBI->connect("dbi:mysql:testDB",'root','') or die "unable $DBI::errstr\n\n";
$password=$cgi-> param ('password')  || '';
$testname=$cgi-> param ('username') || '';
$submit=$cgi-> param ('submit')  || '';
$sth=$dbh-> prepare("Select username,password from user where username='$testname' and password='$pasword'");
$sth-> execute();
$found=0;
while($row=$sth->fetchrow_hashref)
{$found=1;}
if($found = 1)
{
print "Content-type: text/html\n\n";
print <<HTML;
<html>
<head>
<title>test page </title></head>
<body>
<h1> A Simple Perl CGI </h1>
<P> Hello World </P>
</body> </html>
HTML
}
exit;                                                                                     
[root@HP-UX646UU cgi-bin]#

And my html code is:
Code:

[guest@HP-UX646UU zulfi]$ cat login.html
<HTML>
<HEAD>
<TITLE> LOGIN PAGE </TITLE>
</HEAD>
<BODY>
<FORM method ="POST" action="http://localhost/cgi-bin/test.pl">
<TABLE BORDER = "0">
<TR> <TD> USER Name</TD>
<TD><input type="text" name="username" value=""></TD>
</TR>
<TR>
<TD>PASSWORD</TD>
<TD><input type="text" name="password" value=""></TD>
</TR>
<TR><TD COLSPAN="2" ALIGN="RIGHT">
<input type ="submit" name="submit" value="login">
</TD></TR></TABLE></FORM></BODY></HTML>
[guest@HP-UX646UU zulfi]$

I have first opened the html file through browser's file open option and then filled the form and clicked the submit button.

Thanks for helping me.

Zulfi.

jmc1987 11-02-2013 09:22 AM

Glad I can help.

All though I do want to point out, before you get to serious with your form, it is still very insecure. Sanitize your database inputs, to prevent SQL injections.

http://bobby-tables.com/


All times are GMT -5. The time now is 11:03 AM.