CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
problem escaping a special character


New User

Nov 5, 2008, 7:29 AM

Post #1 of 2 (902 views)
problem escaping a special character Can't Post

I have an input box and if I insert for example the word o'clock in the input box and I1 click on a button, the word o'clock is stored in a variable $time.
Now i do an sql to update my database as follows:
UPDATE Persons SET name='$time', WHERE id=1
In my database the word is not inserted because of the special character single quote in the word (').
Can anyone please tell me how to escape the single quote in the word o'clock stored in the variable $time

(This post was edited by zizu on Nov 5, 2008, 7:53 AM)

Veteran / Moderator

Nov 5, 2008, 8:01 AM

Post #2 of 2 (895 views)
Re: [zizu] problem escaping a special character [In reply to] Can't Post

You could either use placeholders and put $time in the execute statement or use the quote() method provided in the $dbh object.

$sth = $dbh->prepare("UPDATE Persons SET name=?, WHERE id=?)"; 
$sth->execute($time, 1);

$time = $dbh->quote($time); 
$sth = $dbh->prepare("UPDATE Persons SET name=$time, WHERE id=1");


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives