?
Solved

Writing to database

Posted on 2003-03-27
13
Medium Priority
?
175 Views
Last Modified: 2010-03-05
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
Comment
Question by:tylerk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 3
  • 2
13 Comments
 
LVL 2

Expert Comment

by:Itatsumaki
ID: 8219249
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
 

Author Comment

by:tylerk
ID: 8220224
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
 

Author Comment

by:tylerk
ID: 8220228
I understand the rest of it though.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:tylerk
ID: 8220533
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
 
LVL 1

Accepted Solution

by:
OKSD earned 260 total points
ID: 8222158
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
 
LVL 1

Expert Comment

by:OKSD
ID: 8222169
Woops, replace that last line with (print "</html>";)

OKSD
0
 

Author Comment

by:tylerk
ID: 8241689
Thank you very much.
0
 
LVL 1

Expert Comment

by:OKSD
ID: 8246481
Sure thing, if you need anything else, let me know :D

OKSD
0
 

Author Comment

by:tylerk
ID: 8248967
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
 

Author Comment

by:tylerk
ID: 8249362
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
 

Author Comment

by:tylerk
ID: 8249400
What is the best way to do it because I don't have a clue?
0
 
LVL 2

Expert Comment

by:Itatsumaki
ID: 8249500
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
 

Author Comment

by:tylerk
ID: 8250538
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

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question