--- j0hncage <[EMAIL PROTECTED]> wrote:

> I have a MySQL database that I'm querying with PHP and have
> encountered a problem that I haven't found a solution for.  It relates
> to an ability to use a single quote to denote feet and double quote
> for inches.   The initial input form inputs the info to the table very
> well and reads fine in another query but on another `update' form
> where the table data is queried and placed by default in respective
> cells for a database update, I can't seem to read the feet and inches
> characters back to a respective field properly.  When it encounters a
> single quote to denote feet ('), it leaves off any characters after
> that point which then upon clicking 'update' places erroneous
> information into the database.
> 
> In the code for this particular task, I've tried using a single quote,
> backslash, etc outside the <> but no luck where reading back to the
> update form cell is concerned.  Anyone have a surefire fix where,
> regardless what characters may reside in a database table, PHP will
> interpret them and bring them back accordingly to a form cell?
> 
> The code I'm currently using is below.  By changing from a double
> quote outside of the <> brackets to a single quote, I was able to read
> a double quote back to the update form field for so many inches but
> the single quote denoting `feet' has created havoc (thought I might
> have it when I did away with the quotes outside of the <> but the
> issue returned (strange that it would work and then suddenly the
> problem comes back though the code didn't change).  An example of what
> I'm trying to echo back to the form cell might be (20 inches by 30
> feet, 4 inches) 20" x 30' 4" - everything else populates just fine. 
> Just a feet and inches thing with the single and double quotes but
> there must be a way around it.
> 
> //toward top of form below query:
> $beltsize = mysql_result($result,$i,"beltsize");
> 
> //lower by the appropriate update form field (html/php)
> <input type="text" name="beltsize" value='<? echo $beltsize ?>' >
> 
> thanks VERY much for any pointers.
> john


When placing the data in the table you will use mysql_real_escape_string() or
addslashes() to escape special characters like the single quote.  Remember
stripslashes() to reverse the action.

To solve your update form situation you want htmlentities() which will convert
special characters to entities (eg " => &quot;).  If you change your input line
to:

<input type="text" name="beltsize" value="<?php echo htmlentities($beltsize);
?>">

you should have better success.

James

Reply via email to