Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Problems displaying data in form values

Php Mysql

3:14 am on Nov 7, 2009 (gmt 0)

Junior Member

10+ Year Member

joined:June 12, 2004
posts: 119
votes: 0

I have a fair knowledge of PHP and MYSQL, but having lots of escape issues when used with forms. Take a simple name and address database with the name John O'Conner.

$fullname = "John O'Conner";
$result = mysql_query("update namedb SET name = '".mysql_real_escape_string($fullname)."' WHERE key = 33 LIMIT 1;");

Now I'll display that in a FORM text field:

$result = mysql_query("select name from namedb WHERE key = 33");
$row = mysql_fetch_assoc($result);
<form ...>
Updated Name: <input type="text" name="fullname" value="<? echo $row['name']; ?>">

I get this:

Updated Name: John O

Everything after the "O" is gone. If I look at the source, the full name is there. So I change my code by changing the the double quotes to singles right before the PHP code:

Updated Name: <input type="text" name="fullname" value='<? echo $row['name']; ?>'>

I get the name returned properly. However, if I change John O'Conner to John O"Conner, I have the same exact problem. I could filter out the quotes, but I have other fields that can have either a single or double quote. What is the solution here? Or what am I doing wrong?

3:34 am on Nov 7, 2009 (gmt 0)

New User

5+ Year Member

joined:June 28, 2008
votes: 0



instead of


your browser is probably confused.

4:31 am on Nov 7, 2009 (gmt 0)

Junior Member

10+ Year Member

joined:June 12, 2004
posts: 119
votes: 0

I tried it both ways!

If I make it value="..." and then the name is John O"Conner, I get the same exact problem: John O

4:49 am on Nov 7, 2009 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member themadscientist is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Apr 14, 2008
votes: 62

$fullname = "John O'Conner";
$fullname = htmlentities($fullname,ENT_QUOTES);
echo $fullname;