Writing to database

Hello I wanted to write the information to a database when the submit button is clicked on this code.


<html>
<head>
<title>Sign Up</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="" onSubmit="return verify(this.username, this.password, this.confirmpassword)">
  <table width="75%" border="0">
    <tr>
      <td width="17%">Enter User Name:</td>
      <td width="83%">
        <input type="text" name="username">
      </td>
    </tr>
    <tr>
      <td width="17%">Enter Password:</td>
      <td width="83%">
        <input type="password" name="password">
      </td>
    </tr>
    <tr>
      <td width="17%">Confirm Password:</td>
      <td width="83%">
        <input type="password" name="confirmpassword">
      </td>
    </tr>
    <tr>
      <td width="17%"> </td>
      <td width="83%">
        <input type="submit" name="Submit" value="Submit")>
      </td>
    </tr>
  </table>
</form>
<script language = "javascript">
     function verify(username, password1, password2){
     var passed=false
     if (username.value ==''){
          alert("Please enter a username.")
          username.focus()
     }
     else if (password1.value==''){
          alert("Please enter a password.")
          password1.focus()
     }
     else if (password2.value==''){
          alert("Please verify the password")
          password2.focus()
     }
     else if (password1.value!=password2.value){
          alert("The two passwords do not match")
          password1.select()
     }
     else
          passed=true
          return passed
     }
</script>
</body>
</html>

I was wondering how this would be done in Perl?? This will have to be done with a MS-Access database.  I need some code provided.  Thank you very much.
tylerkAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ItatsumakiCommented:
1. Set up the ODBC connection (if using MS-Access make it a system DSN)
2. install DBI
If you use ActivePerl go to a dos prompt and type:
ppm install DBI
then
ppm install DBD-ODBC
and the two modules you need will be installed
3. write scripts to use DBI
For example to access an MS-Access table your script might look something like this:

use DBI;
use strict;

my $user = '';
my $pass = '';
my $connect = 'dbi:ODBC:testDB';

my $dbh = DBI->connect($connect, $user, $pass);
my $sql = 'SELECT employee FROM employees';
my $sth = $dbh->prepare($sql);

$sth->execute();

while (my $employee = $sth->fetchrow_array()) {
   print "$employee\n";
   }
0
tylerkAuthor Commented:
I am sorry I am not too sure what this line means.
1. Set up the ODBC connection (if using MS-Access make it a system DSN)
0
tylerkAuthor Commented:
I understand the rest of it though.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

tylerkAuthor Commented:
I could not install DBI or DBD-ODBC so I want to now use a text file instead.  This site does not need much security so it will be fine.  So if anyone knows how to use a text file instead of a database that would be good.  Thank you.
0
OKSDCommented:
Yeh, I do that all the time:

Here's how to write to it:

#/usr/bin/perl
$dbfile = "database.txt";
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@stuff = split(/&/, $buffer);
foreach $data (@stuff) {
   ($name, $value) = split(/=/, $data);
$value =~ tr/+/ /;
   $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
   $value =~ s/<!--(.|\n)*-->//g;
$DATA{$name} = $value;
}
open(FILE, ">>$dbfile") || print "Error opening database file!";
print FILE "null=null&username=$DATA{username}&password=$DATA{password}&null=null|ENTRY|";
close(FILE);

and to read from it:

#/usr/bin/perl
$dbfile = "database.txt";
open(FILE, "$dbfile") || print "Error reading database!";
@lines = <FILE>;
close(FILE);
$file = "@lines";
print "Content-type: text/html\n\n";
print "<html>\n";
@entries = split(/\|ENTRY\|/, $file);
foreach $entry (@entries) {
@pairs = split(/&/, $entry);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$file{$name} = $value;
}
print "<b>Username:</b> $file{username}<br><b>Password:</b> $file{password}<p>";
}
print "<html>";

That should work, let me know if you need anything else.

Also, please note that this is nowhere near secure.

OKSD
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
OKSDCommented:
Woops, replace that last line with (print "</html>";)

OKSD
0
tylerkAuthor Commented:
Thank you very much.
0
OKSDCommented:
Sure thing, if you need anything else, let me know :D

OKSD
0
tylerkAuthor Commented:
Hey I was wondering how to search throught the text file to find the user name when the user tries to login??  Thank you.
0
tylerkAuthor Commented:
I just realized that this whole thing isn't going to work because all that will happen when they enter their user name and password is they will get sent to a url.  If they were to type in that url they would be able to get in without entering a user name or password.  Is there a way to pass the user name and password to javascript??
0
tylerkAuthor Commented:
What is the best way to do it because I don't have a clue?
0
ItatsumakiCommented:
You have asked three different questions and received appropriate answers for them.

> This will have to be done with a MS-Access database.  I need some code provided.  Thank you very much.

I provided the correct code.

You then responded that this would not work -- and asked to change the question.  In all likelihood we could have gotten your DBI install working.  Instead, you asked an separate question:

> I could not install DBI or DBD-ODBC so I want to now use a text file instead.

OKSD gave the correct answer, which you accepted.

And now you're asking the whole thing over again!!!

Separate questions need to be asked separately and points given appropriately.  Your best bet, imho, was to get the database working at the beginning.  But you can *definitely* do this with a text-file.
0
tylerkAuthor Commented:
Yes I know that I have asked three different questions.  I have recieved excellent answers and I am thankful for that.  I am a little bit confused and am new to this so I am sorry I am not as good at it as you but there is no need to be a dick about it.  And what does imho mean anyway?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.