Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

' can't save in db

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

' can't save in db

Postby ppkkyaw » Sat Oct 12, 2013 8:57 pm

Hello guys

When I try to save
"I don't think so"
word to my db

it can't save. may be because of " ' " word

how do I do?
ppkkyaw
New php-forum User
New php-forum User
 
Posts: 9
Joined: Tue Aug 21, 2012 4:25 pm

Re: ' can't save in db

Postby Cygnush33l » Mon Oct 14, 2013 3:59 am

You need to escape your string before entry to the database. E.g
Code: Select all
$string = mysqli_real_escape_string("I don't think so");

This will output the string like
I don\'t think so

http://www.php.net/manual/en/mysqli.real-escape-string.php
Cygnush33l
New php-forum User
New php-forum User
 
Posts: 1
Joined: Mon Oct 14, 2013 3:54 am

Re: ' can't save in db

Postby ppkkyaw » Tue Oct 29, 2013 4:27 am

$string = mysqli_real_escape_string("I don't think so");
will be saved into database as

I don\'t think so

however, it would be problem when we retrieve it from database and display to the user because user saved as

I don't think so

the code will saved and display as

I don\'t think so

how do I make it correct?
I mean how can i retrieve it as original string (I don't think so) ???

help me guys
ppkkyaw
New php-forum User
New php-forum User
 
Posts: 9
Joined: Tue Aug 21, 2012 4:25 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Strider64 and 3 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.