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(); } }
In reply to working with a database by jrp370
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |