Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl -wT
- use DBI;
- $db="int420_101a20";
- $user="int420_101a20";
- $passwd="18639171";
- $host="db-mysql.zenit";
- $connectionInfo="dbi:mysql:$db;$host";
- print "Content-type:text/html\n\n";
- if ($ENV{REQUEST_METHOD} eq "GET")
- {
- &browsecatalog;
- }
- else
- {
- &parseform;
- if ($form{submit} eq "Buy")
- {
- if ($ENV{"HTTP_COOKIE"})
- {
- &showcheckout;
- }
- else
- {
- &showlogin;
- }
- }
- elsif ($form{submit} eq "login")
- {
- if (&validateuser)
- {
- &sendlogincookie;
- &showcheckout;
- }
- else
- {
- &showlogin;
- }
- }
- elsif ($form{submit} eq "checkout")
- {
- if (&validatecheckout)
- {
- &insertransaction;
- &emailreceipt;
- &showreceipt;
- }
- else
- {
- &showcheckout;
- }
- }
- }
- sub browsecatalog
- {
- print qq~
- <html>
- <title>Ninja Warehouse Inventory</title>
- </head>
- <body bgcolor="black">
- <font color="white">
- <center>
- <br>
- <h1> Ninja Items </h1>
- <br>
- <br>
- <table border cellpadding=10>
- <tr style="color:#00FF00">
- <th>ID Number</th><th>Prod Name</th><th>Description</th><th>Price</th><th>Picture</th><th>Options</th>
- </tr>~;
- $select=qq~select id, idnum, name, descr, price, pic from inventory order by idnum;~;
- $dbh=DBI->connect($connectionInfo,$user,$passwd);
- $sth=$dbh->prepare($select);
- $sth->execute();
- while (@row=$sth->fetchrow_array())
- {
- print qq~
- <tr style="color:#00FF00"><td>$row[1]</td><td>$row[2]</td> <td>$row[3]</td> <td>\$ $row[4]</td> <td><img src="/img/$row[5]"/></td>
- <td>
- <form action="stage4.cgi" method="post">
- <input type="hidden" name="id" value="$row[0]">
- <input type="submit" name="submit" value="Buy">
- </td>
- </tr>~
- }
- print qq~
- </table>
- </body>
- </html>
- ~;
- }
- sub parseform
- {
- read(STDIN, $qstring, $ENV{'CONTENT_LENGTH'});
- @pairs = split(/&/, $qstring);
- foreach (@pairs) {
- ($key, $value) = split(/=/);
- $value =~ tr/+/ /;
- $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
- $form{$key} = $value;
- }
- }
- sub showlogin
- {
- print qq~
- <html>
- <head>
- <title>Ninja Warehouse</title>
- </head>
- <body bgcolor="black">
- <form action="stage4.cgi" method=POST>
- <p>
- <font color="white">
- <center>
- <h2>Ninja Warehouse Customer Registration</h2>
- <table border = "0">
- <tr style="color:#00Ff00"><td> Login Name: </td><td><input type=text name=logn value="$form{logn}" ></td><td> $errors{logn}</td><td> $found</td>
- </tr>
- <tr style="color:#00Ff00"><td> Password: </td><td><input type=text name=passw value="$form{passw}"></td><td> $errors{logn}</td>
- </tr>
- </table>
- </font>
- <input type=submit value="login" name"login">
- </form>
- </p>
- </center>
- </body>
- </html>
- ~
- }
- sub validateuser
- {
- $dbh=DBI->connect($connectionInfo,$user,$passwd);
- $select=qq~select * from customers where logn='$form{logn}'~;
- $sth=$dbh->prepare($select);
- $sth->execute;
- if ($row=$sth->fetchrow_arrayref)
- {
- $found = "Username found"
- }else{
- $found = "Username Not found"
- }
- }
- sub sendlogincookie
- {
- }
- sub showcheckout
- {
- print qq~
- <html>
- <h2> "Checkout here"</h2>
- </html>
- ~
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement