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!
Quotations inside a MySQL database
Moderator: General Moderators
- 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
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
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
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!
Thanks in advance!
-
devendra-m
- Forum Contributor
- Posts: 111
- Joined: Wed Sep 12, 2007 3:16 am
Re: Quotations inside a MySQL database
base64_encode()
base64_ decode()
base64_ decode()
Re: Quotations inside a MySQL database
use mysql_real_escape_string($str) function to escape values contains single quote or double quote etc.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!
For more PHP Answers
Re: Quotations inside a MySQL database
use mysql_escape_string() function to escape all single quote and double quote values in string
For more PHP Answers
For more PHP Answers