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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.