Forum Moderators: coopster & phranque

Message Too Old, No Replies

opening an html file with perl/cgi

         

aline

9:40 pm on Jul 20, 2003 (gmt 0)

10+ Year Member



I have a perl script that checks what the user has entered. The idea is to check the user's details and then either have some text appearing saying that their details are not correct or if they are automatically send them to the main page of the website which is an html file.
So the question is how do I automatically load this html page without using a "A href"? I read I could use a redirect header but then it would skip the process of checking details. Is there anyway of doing this or do I have to use a A Href?

Thanks.

tschild

12:23 am on Jul 21, 2003 (gmt 0)

10+ Year Member



I'd go for a script, called by the form, on the following lines:


#!/usr/bin/perl
use CGI qw(:standard);

# read form parameters and check them.
# Code for this goes here.

if($DetailsAreCorrect) {
print redirect(-location=>'http://www.yoursite.com/');
}
else {
print header(); # HTTP headers
print start_html('Sorry, something wrong with your input')
# print HTML page explaining errors,
# including new input form.
# Code for this goes here.
print end_html();
}

SinclairUser

1:03 am on Jul 21, 2003 (gmt 0)

10+ Year Member



If you are saving the data that the user enters in a database then you need to check they dont hit submit more than once. Otherwise you will get the entry twice or an insert error.

aline

10:20 am on Jul 21, 2003 (gmt 0)

10+ Year Member



Thank you so much, It is working perfectly!
Thanks again.

aline

10:33 am on Jul 21, 2003 (gmt 0)

10+ Year Member



Well, I thought it was working! It goes directly to the new page without checking the details. The code is as follows:
#!c:/perl/bin/perl.exe
use DBI;
$,="\t";
use CGI ":standard";
$username=param("username");
$password=param("password");
$condition;
$cond;
$id;
$unicode;

$db=DBI->connect("dbi:mysql:administration") or die"\n Error($DBI::err):$DBI::errstr\n";

$aquery="select pass from password where username='$username'";
$vquery="select id, unicode from password where username='$username'";

$a=$db->prepare($aquery);
$a->execute();
while(@result=$a->fetchrow())
{foreach $result(@result)
{
if ($result =$password)
{$condition=1;
}

}
}

$b=$db->prepare($vquery);
$b->execute();
while(@bresult=$b->fetchrow())
{
$id=$bresult[0];
$unicode=$bresult[1];
}

if($condition==1)
{print redirect(-location=>'http://localhost/homepage.html');
}

else
{print"content-type:text/html\n\n";
print"<html>\n";
print"<body bgcolor=\"#990000\"><font color=\"white\">";
print "Sorry but your password does not match your username. Please try again. <br><form action=\"login.pl\" method=\"post\" target=\"mainFrame\">Username: <input type=\"text\" name=\"username\" size=\"15\"><br><br><br>
Password: <input type=\"password\" name=\"password\" size=\"15\"><br><br><br><center>
<input type=\"submit\" value=\"Submit\"></form></center>" ;

}

$a->finish();
$b->finish();

$db->disconnect();

Where is my mistake? :-)

aline

11:06 am on Jul 21, 2003 (gmt 0)

10+ Year Member



Well I'm ashamed to say it didn't work because the query to the database was wrong. It is totally working now so thanks again!

tschild

1:25 pm on Jul 21, 2003 (gmt 0)

10+ Year Member



er... your code possibly might not work in some browsers without the </html>.