#!/usr/bin/perl use warnings; use strict; use Data::Dumper; use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); my $username = param('username'); # info from login.html my $cgi = CGI->new; # create CGI object # try and connect to DB my $dbh = DBI->connect("dbi:mysql:database", "username", "password", { RaiseError => 1, AutoCommit => 1 }) or die "Can't connect: $DBI::errstr"); my $select_sth = $dbh->prepare("SELECT loc FROM users WHERE name = ?"); if($cgi->param("action") eq "update") { my $update_sth = $dbh->prepare("UPDATE users SET loc=? WHERE name=?"); my $new_location = $cgi->param("newloc"); $update_sth->execute($new_location, $username); } # Pull player location from db $select_sth->execute($username); # Put player loc into variable based on previous pull my $location = $select_sth->fetchrow_array; print $cgi->header, $cgi->start_html( -title => 'Begin: Eden v2'); print "You are $username and are located at $location"; print $cgi->start_form(); print $cgi->textfield(-name => 'newloc', -size => '4', -value=>$location, -force=>1); print $cgi->hidden('username','username'); print $cgi->hidden(-name=>"action", -value=>"update"); print $cgi->submit(-value => 'name', -alias => 'username'); print $cgi->endform; print $cgi->end_html; $dbh->disconnect(); exit;