Current time: 04-24-2014, 06:32 AM Hello There, Guest! (LoginRegister)

Post Reply 
database question
12-16-2003, 02:27 AM
Post: #1
database question
Hi.

I teach about diabetes and am trying to set up a health website where I can have my clients log on, record their daily sugar numbers, and view their previous sugar numbers. I have no idea where to start with this. Is there a script that I can modify that will let me do this? Where do I start with this? Any help would be much appreciated.
Find all posts by this user
Quote this message in a reply
12-16-2003, 05:49 PM
Post: #2
database question
I woudl doubt there is a specific application you could just install and have work, but this is the perfect opportunity to write a custom script that does just what you need.

I would consider learning about using php and mysql together to create what you need. There is a lot of material our there available for free that you can read up on. You would need the database to keep track of each user for authentication, and also their daily stats.

I would start looking at hotscripts.com - there are a lot of scripts out there that are free, and may work for you to modify.

Have fun! php and mysql are really powerful and relativley easy to use, so dont be afrad to get your feet wet.

Scott
Find all posts by this user
Quote this message in a reply
12-16-2003, 09:05 PM
Post: #3
database question
Here is a simple Perl script I whipped up for a starting point. You would need to put this script in a password-protected directory on your web site. You will also need to setup a MySQL database and change the $database variable. It assumes you have a table called `records` with the following columns: username, timestamp, and sugar_level. The timestamp column is meant to be at least a 32-bit integer, so you should use the INT data type.

This is just an example of how to use a MySQL database in perl as well as create a CGI script using the CGI module. It is not meant to be used as-is and is public domain.
Code:
#!/usr/local/bin/perl

use CGI qw(:all);
use CGI::Carp qw(fatalsToBrowser);
use DBI;

## GLOBALS

my %database = (
'hostname'    => 'localhost',
'name'        => 'diabetes',
'username'    => 'username',
'password'    => 'password'
);

my ($username, $dsn, $dbh, $sth, $row);

$dsn = "DBI:mysql:database=$database{'name'};host=$database{'hostname'}";

print
header(),
start_html();

if ($username = $ENV{'REMOTE_USER'}) {
if ($dbh = DBI->connect($dsn, $database{'username'}, $database{'password'})) {  
if (request_method() eq 'POST') {
&add_record;            
}
&show_records;
$dbh->disconnect;
}
else {
print
h1('Database Error'),
p('Please contact the webmaster.');
}    
}
else {
print
h1('Login Error'),
p('Please contact the webmaster.');
}

print
end_html();

exit;

sub add_record {

if (length param('level') > 0) {
$sth = $dbh->prepare(q{INSERT INTO `records` SET username=?,timestamp=?,sugar_level=?});
if (defined $sth and $sth->execute($username, time, param('level'))) {
print
h1('Success'),
p('Your sugar level for today has been recorded.');
}
else {
print
h1('Database Error'),
p('Please contact the webmaster.');
}
}
else {
print
h1('Form Error'),
p('The form was blank.');
}

return;
}

sub show_records {

my @records;

$sth = $dbh->prepare(q{SELECT * FROM `records` WHERE username=?});
if (defined $sth and $sth->execute($username)) {
while ($row = $sth->fetchrow_hashref) {
push(@records, { %$row });
}
}
else {
print
h1('Database Error'),
p('Please contact the webmaster.');
}

print
start_form(-method=>'POST', -action=>$ENV{'SCRIPT_NAME'}),
p(
'Sugar level:',
textfield(-name=>'level', -size=>'8'),
submit(-value=>'Post')),
endform();

if (@records) {
print table({-cols=>'2',-width=>512},
caption('Daily Sugar Levels'),
Tr({-align=>CENTER,-valign=>TOP},
[
th(['Date', 'Level',]),
(map { td([scalar(localtime($_->{'timestamp'})), $_->{'sugar_level'}]) } @records)
]
)
);

}

return;
}
Cool Perl / MySQL / HTML+CSS
Visit this user's website Find all posts by this user
Quote this message in a reply
12-17-2003, 01:53 AM
Post: #4
database question
wow thanks so much for the help. this gets me started in the right direction. i still have a lot to learn, but thanks again for your time.
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump: