Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/perl
- use strict;
- use CGI;
- use DBI;
- my $q = CGI->new; # suzadava obek ot tip CGI
- print $q->header(); # metoda header vrushta kato text
- my $username = $q->param("username");
- my $password = $q->param("password");
- my $email = $q->param("email");
- my $dbh = DBI->connect("dbi:ODBC:sql_perl", 'sa', 'sa991');
- my $method = $ENV{'REQUEST_METHOD'};
- my $text;
- if ($method eq "GET") {
- $text = $ENV{'QUERY_STRING'};
- }
- else { # default to POST
- read(STDIN, $text, $ENV{'CONTENT_LENGTH'});
- }
- my @value_pairs = split (/&/,$text);
- my %form_results = ();
- my $pair;
- my $key;
- my $value;
- foreach $pair (@value_pairs) {
- ($key, $value) = split (/=/,$pair);
- $value =~ tr/+/ /;
- $value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex ($1))/eg;
- $form_results{$key} = $value; # store the key in the results hash
- }
- $username = $form_results{'username'};
- $password = $from_results{'password'};
- $email = $from_results{'email'};
- my $msg;
- if ($dbh->do("INSERT INTO users values( '${username}', '${password}', '${email}')") ){
- $msg = " You are registered now";
- }
- else{
- $msg = "Error registering";
- }
- print <<EOF;
- <html>
- <body>
- <h2>User Registration</h2>
- <form action="RegistrationForms.pl" method="post" name="RegisterForms">
- <fieldset>
- <legend>Registration</legend>
- <table>
- <tr>
- <td>Username<em>*</em></td>
- <td><input type="text" name="${username}" size="20" id="firstName" /></td>
- </tr>
- <tr>
- <td>Email<em>*</em></td>
- <td><input type="text" name="${email}" size="20" id="email" /></td>
- </tr>
- <tr>
- <td>Password<em>*</em></td>
- <td><input type="text" name="${password}" size="20" id="password" /></td>
- </tr>
- </table>
- <input type="submit" value="Register now" />
- </fieldset>
- </form>
- </body>
- </html>
- EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement