Quotations inside a MySQL database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jaandrws
Forum Newbie
Posts: 9
Joined: Sat Mar 31, 2007 8:13 pm

Quotations inside a MySQL database

Post by jaandrws »

How do I need to handle a query to a mysql database when I know the returned data may possibly contain quotation marks?
Code:
$query1 = "SELECT * FROM photo_log WHERE name = '$version'";
$result1 = mysql_query($query1) or die("Could not perform query: ".mysql_error());
$row1 = mysql_fetch_array($result1);

The returned data is cut off from the point of a quotation mark. THE DATA IS: ITHF's "The Buth" at 2007 Convention.
If I try add slashes after the query, I get: ITHF\'s \
I've tried a bunch of different approaches, but frankly this kind of problem has always confused me. My global_pc and global_runtime are both turned off. Sorry to be a bother! Thanks!
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Re: Quotations inside a MySQL database

Post by Bill H »

display the output using

Code: Select all

htmlentities(stripslashes($row1['field']),ENT_QUOTES)
devendra-m
Forum Contributor
Posts: 111
Joined: Wed Sep 12, 2007 3:16 am

Re: Quotations inside a MySQL database

Post by devendra-m »

If you encode string before save and decode after retrieval using base64 encoding, you will have no problem with string of any characters.
verymeanguy
Forum Newbie
Posts: 6
Joined: Sat Jul 19, 2008 5:40 am

Re: Quotations inside a MySQL database

Post by verymeanguy »

I am very new to php but I think this will be very important to me in the future. So, how does one encode and decode a piece of string use base 64 encoding in php?

Thanks in advance!
devendra-m
Forum Contributor
Posts: 111
Joined: Wed Sep 12, 2007 3:16 am

Re: Quotations inside a MySQL database

Post by devendra-m »

base64_encode()
base64_ decode()
padduweb
Forum Newbie
Posts: 7
Joined: Mon Jul 21, 2008 2:27 am

Re: Quotations inside a MySQL database

Post by padduweb »

jaandrws wrote:How do I need to handle a query to a mysql database when I know the returned data may possibly contain quotation marks?
Code:
$query1 = "SELECT * FROM photo_log WHERE name = '$version'";
$result1 = mysql_query($query1) or die("Could not perform query: ".mysql_error());
$row1 = mysql_fetch_array($result1);

The returned data is cut off from the point of a quotation mark. THE DATA IS: ITHF's "The Buth" at 2007 Convention.
If I try add slashes after the query, I get: ITHF\'s \
I've tried a bunch of different approaches, but frankly this kind of problem has always confused me. My global_pc and global_runtime are both turned off. Sorry to be a bother! Thanks!
use mysql_real_escape_string($str) function to escape values contains single quote or double quote etc.

For more PHP Answers
padduweb
Forum Newbie
Posts: 7
Joined: Mon Jul 21, 2008 2:27 am

Re: Quotations inside a MySQL database

Post by padduweb »

use mysql_escape_string() function to escape all single quote and double quote values in string

For more PHP Answers
Post Reply