user2673161
user2673161

Reputation: 1695

Perl 5 Get input from user and delete from table in database

I have a simple Perl script, I simply want to get the input from the user terminal style and use that to delete a row within the table in the database, here is the code snippet:

# something not right here..
my $name = <STDIN>;

my $sth3 = $dbh->prepare("DELETE FROM animals WHERE animal_name = ?");

$sth3->bind_param(1, $name);

$sth3->execute() or die 'nope...';
print $sth3->rows;
$sth3->finish();

The connection is working, however, the query will not pick up the value to delete so 0 rows are always returned. Any help would be nice with this, I believe I am going about this the right way but making a small mistake in binding this to the query. Thank you in advance.

Upvotes: 1

Views: 191

Answers (1)

Chankey Pathak
Chankey Pathak

Reputation: 21666

You need to chomp the input. Do

my $name = <STDIN>;
chomp($name);

or

chomp(my $name = <STDIN>);

Upvotes: 2

Related Questions