Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 177
  • Last Modified:

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.
0
tylerk
Asked:
tylerk
  • 8
  • 3
  • 2
1 Solution
 
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 8
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now