jrp370 has asked for the wisdom of the Perl Monks concerning the following question:
im working with a database to do a simple phonebook most of functions work perfectly however im running into a problem with the add entry function it is intended to stop a user from entering the same name twice and it works fine while youre running the program however once you close the program down and start it up again it will let you enter in a name that is already in the database. can anyone point me in the right direction for modifying my code to prevent this?
sub addEntry { print"Please enter their name: \n"; chomp (my $name = <STDIN>); $name = lc($name); if (exists $phonebook{$name}){ print"$name is already in your phonebook\n"; } else { print"Please enter their phone number (123 4567): \n"; chomp (my $phone = <STDIN>); $phonebook{$name} = $phone; my $sth; # statement handle $sth = $dbh->prepare('INSERT INTO Phonebook (name, Phone) VALUES (?, ?)' ) or die "Can't prepare SQL: " . $dbh->errstr(); $sth->execute("$name", "$phone") or die "Can't execute SQL: " . $sth->errstr(); $sth->finish(); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: working with a database
by GrandFather (Saint) on Feb 10, 2012 at 00:20 UTC | |
|
Re: working with a database
by JavaFan (Canon) on Feb 10, 2012 at 00:22 UTC | |
|
Re: working with a database
by Anonymous Monk on Feb 10, 2012 at 00:13 UTC |