PHP/Mysql/special characters problem

From: Mosher (mosh_king2000_at_yahoo.com)
Date: 12/31/03


Date: Wed, 31 Dec 2003 13:33:23 -0600

Hi all,

I have an issue with php and/or mysql. I have a php form that writes "items"
to a mysql database, including a description of the item. On the mysql
server, "magic_quotes_gpc" is ON.

I am testing it now by putting special characters in the description field,
this is what I am entering:

O'Leary "special edition"

Now, this item data always gets written to the db just fine and shows up in
the db as entered. Seems correct and working just fine up to this point.

My problem is with my "edit item" page. This page allows users to update
items, including the mentioned "description" field. But when the data is
called back up from the db to display in the "edit item" page and the
description contains double quotes, the description is cut off, and only
shows:

O'Leary

Here is the code (snippet of the important stuff and numbered) on the "edit
item" page:

1. $result = mysql_query("select * from inven where product =
'$product'");
2. $row = mysql_fetch_array($result);
3. echo "Description is: $row[description]";
4. echo "<table width=80% border=1 cellpadding=4 cellspacing=0>";
5. ?>
6. <tr><td>Product #:</td><td><input type=text name=product value="<?echo
$row[product]?>"></td></tr>
7. <tr><td>Description:</td><td><input type=text name=description
value="<?echo $row[description]?>" size=50></td></tr>
8.
9. <?
10. echo "</table>";
11. echo "<br><br><input type=submit name=Update value=Update>";
12. ?>

The important line of code here is line 6, where the value of description
should show. The real value of description that is in the database should be
showing up here, but it is cut off if it contains double quotes. Note also
that the full value (double quotes and all) of description can be seen in
the echo statement at line 3. I'm stumped.

To sum up this problem, data appears to get written to the db just fine. The
"edit item" page is brought up, but the description - if it contains special
characters, is cut off, apparently where there are double quotes. If I go
ahead and update the item, the new value in the db is now cut off and not
what I want.

Any ideas? Thanks in advance.

Mosher



Relevant Pages

  • Re: How do I escape parentheses in a mysql query?
    ... SELECT * FROM tblCustomers WHERE InactiveFlag = "0" ... Double quotes are a non-standard MySQL extension to the spec. ...
    (comp.lang.php)
  • Re: Fetch 6 records from a table randomly
    ... critical details (e.g. what sort of table? ... "I have a table 'documents' stored in a MySQL database that I'm accessing ... I haven't been able to find a function in Ruby to pick a random element. ...
    (comp.lang.ruby)
  • Re: sarge + postfix + mysql
    ... >So when postfix/courier is doing a mysql database lookup, ... >'vmail' that is only allowed to log in from localhost and has no ... >permissions for accessing the database 'provider'. ...
    (Debian-User)
  • RE: CGI::Session
    ... > some hashes in a MySQL database, ... > other visitor preferences like the font style, colors, font ... > in a MySQL record than the session ID? ... transmitted without the written permission of the copyright owner. ...
    (perl.beginners)
  • Re: sarge + postfix + mysql
    ... If you are using postfix 2.2.x the sintax of the .cf files may be different. ... > So when postfix/courier is doing a mysql database lookup, ... > permissions for accessing the database 'provider'. ...
    (Debian-User)