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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



zizu
New User

Nov 5, 2008, 7:29 AM

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

Hello,
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)


FishMonger
Veteran / Moderator

Nov 5, 2008, 8:01 AM

Post #2 of 2 (292 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.


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



Code
$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