#!/usr/bin/perl use DBI; $user = "test"; $db = "test"; $host = "localhost"; $password = "test"; print "Content-type: text/html\r\n\r\n"; # First display a form print "User-Age"; print "

Name:
\n Age:
\n
\n

"; # Get any data (if) from %ENV{"QUERY_STRING"} @strings = split (/&/, $ENV{"QUERY_STRING"}); foreach $assignment (@strings) { ($name,$value) = split (/=/, $assignment); $GET{$name} = $value; } $connection = DBI->connect ("DBI:mysql:$db:$host", "$user", "$password") or die ("Error in db connection.\n"); if ($GET{"name"} ne "") { #if something has been sent, then enter it into database. #this assumes a table named name_age which has a name (varchar) #field and a age (int) field. $query = "insert into name_age values (\"$GET{\"name\"}\", $GET{\"age\"})"; $execute = $connection->prepare ($query); $result = $execute->execute() or die ("DB query failed.\n"); } print "Current database status:
\n"; $query = "select * from name_age"; $execute = $connection->prepare ($query); $execute->execute() or die ("DB query failed.\n"); while (@row = $execute->fetchrow_array) { print "@row
\n"; } print " ";