LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 10-30-2013, 05:45 AM   #1
zak100
Member
 
Registered: Jul 2009
Posts: 171

Rep: Reputation: 2
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.
 
Old 10-31-2013, 12:22 AM   #2
Mousepad123
LQ Newbie
 
Registered: Oct 2012
Distribution: CentOS or Debian
Posts: 23

Rep: Reputation: 3
Please check your perl syntax with the following code:

Code:
perl -c login.pl
 
Old 11-01-2013, 02:13 AM   #3
zak100
Member
 
Registered: Jul 2009
Posts: 171

Original Poster
Rep: Reputation: 2
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.
 
Old 11-01-2013, 05:30 AM   #4
PeterSullivan
LQ Newbie
 
Registered: Aug 2013
Posts: 29

Rep: Reputation: Disabled
Quote:
Originally Posted by Mousepad123 View Post
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
 
Old 11-01-2013, 11:27 PM   #5
zak100
Member
 
Registered: Jul 2009
Posts: 171

Original Poster
Rep: Reputation: 2
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.
 
Old 11-02-2013, 01:16 AM   #6
jmc1987
Member
 
Registered: Sep 2009
Location: Oklahoma
Distribution: Debian, CentOS, windows 7
Posts: 866

Rep: Reputation: 110Reputation: 110
Quote:
Originally Posted by zak100 View Post
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.
 
Old 11-02-2013, 02:09 AM   #7
jmc1987
Member
 
Registered: Sep 2009
Location: Oklahoma
Distribution: Debian, CentOS, windows 7
Posts: 866

Rep: Reputation: 110Reputation: 110
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.
 
Old 11-02-2013, 04:17 AM   #8
zak100
Member
 
Registered: Jul 2009
Posts: 171

Original Poster
Rep: Reputation: 2
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.
 
Old 11-02-2013, 09:22 AM   #9
jmc1987
Member
 
Registered: Sep 2009
Location: Oklahoma
Distribution: Debian, CentOS, windows 7
Posts: 866

Rep: Reputation: 110Reputation: 110
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/
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
php5 problem with uploads from IE using html form input type file miedward Programming 3 04-06-2010 01:24 PM
PHP: html Form Select function problem camlinux Programming 2 05-15-2005 08:23 PM
Contact form on HTML Gerardoj Linux - General 1 03-26-2004 02:08 AM
an html form question matt_w_lambert Programming 3 10-30-2003 11:41 PM
problem with html form meluser Linux - Software 4 03-15-2003 12:28 PM


All times are GMT -5. The time now is 09:45 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration