commit f80ac5c8b2d67b05f078660e0c4ab566009afd8d Author: piratefinn Date: Fri Aug 12 17:10:42 2016 +0100 First commit diff --git a/senddatatodb.pl b/senddatatodb.pl new file mode 100644 index 0000000..479de6b --- /dev/null +++ b/senddatatodb.pl @@ -0,0 +1,37 @@ +#!/usr/bin/env perl + +use Mojolicious::Lite; + +# connect to database +use DBI; +my $dbh = DBI->connect("dbi:Pg:dbname=$foodloop","","") or die "Could not connect"; + +# shortcut for use in template +helper db => sub { $dbh }; + +# setup base route +any '/' => 'index'; + +my $insert; +while (1) { + # create insert statement + $insert = eval { $dbh->prepare('INSERT INTO foodloop (user, company, currency) VALUES (?,?,?)') }; + # break out of loop if statement prepared + last if $insert; + + # if statement didn't prepare, assume its because the table doesn't exist + warn "Creating table 'foodloop'\n"; + $dbh->do('CREATE TABLE foodloop (user varchar(255), company varchar(255), currency int, filename varchar(255));'); +} + +# setup route which receives data and returns to / +post '/' => sub { + my $self = shift; + my $user = $self->param('user'); + my $company = $self->param('company'); + my $company = $self->param('currency'); + $insert->execute($user, $company, $currency); + $self->render(text => 'It did not kaboom!'); +}; + +app->start; diff --git a/uploadimage.pl b/uploadimage.pl new file mode 100644 index 0000000..9a3fc67 --- /dev/null +++ b/uploadimage.pl @@ -0,0 +1,19 @@ +#!/usr/bin/env perl +use Mojolicious::Lite; + +# /?user=sebastian&pass=secr3t +any '/' => sub { + my $c = shift; + + # Query parameters + my $user = $c->param('user') || ''; + my $company = $c->param('company') || ''; + my $currency = $c->param('currency') || ''; + print "$user $company $currency\n"; + use Devel::Dwarn; + Dwarn $c->req; + # Failed + $c->render(text => 'upload failed.'); +}; + +app->start;