How to use $dbh->quote, or, secure web I/O in Perl

Hello,
I have a CGI script for a website which has lines like this:

$sth=$dbh->prepare (qq{ INSERT INTO people VALUES (NULL,’$name’,’$city’,’$state’,’$country’) } ).

Now, for example, if the name fields input was “O’Reilly”, this script would fail. I’ve been told on another website to use the $dbh->quote method for this - can anyone show me how to, please?

Thanks very much.