Reputation: 1695
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
Reputation: 21666
You need to chomp the input. Do
my $name = <STDIN>;
chomp($name);
or
chomp(my $name = <STDIN>);
Upvotes: 2