Click to See Complete Forum and Search --> : [RESOLVED] Quote Trouble in form?


tjmcd
01-13-2007, 09:13 PM
Hey All,

Owing to the existence of single and double quotes in our product names, I'm having a time echoing the full contents of the field
<input name="product" value="<?php echo $_product;?>" size="100"> in the following form.
Unfortunately, this is a problem as MOST of the product names WILL contain double and or single quotes.
For a product named Girls' 16" Huffy Disney Princess Bike -- for example, I get only Girls' 16. How might I get around this?
I have seen use of CURLY BRACES to call php variables, but can't seem to find references to it just now.

Please:D

<?php
if (isset($_POST['submit'])) { // Handle the form.
require_once ('mysql_connect.php');
mysql_select_db ('bike_shop');
$result = mysql_query('SELECT * FROM catalog');
// Fetch record rows in $result by while loop and put them into $row.
while($row = mysql_fetch_array($result)) {
$_product = "$row[Product]";
$_edit_descr = "$row[Description]";

}
echo $_product;
}

?>
<html>
<head>
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="update.php">
<table border="1" cellpadding="3" cellspacing="0" width="691">
<tr>
<td align="center" bgcolor="#FFCC00" width="269"><strong>ID</strong></td>
<td align="center" bgcolor="#FFCC00"><strong>Description</strong></td>
</tr>
<tr>
<td bgcolor="#FFFFCC" width="269">
<input name="product" value="<?php echo $_product;?>" size="100"></td>
<td bgcolor="#FFFFCC"><textarea rows="5" cols="43"><?php echo $_edit_descr; ?></textarea>
</td>
</tr>
</table>
<input type="submit" name="Submit" value="Update" />
</form>
</body>
</html>

NightShift58
01-13-2007, 09:33 PM
If the data/product names are entered manuall, you'll have to use mysql_real_escape_string() prior to inserting/updating in your database.

When you retrieve the data from your database, use stripslashes() to remove the extraneous escape characters from the record data.

Before escaping: Girls' 16" Huffy Disney Princess Bike
After escaping: Girls\' 16\" Huffy Disney Princess Bike
After stripping slashes: Girls' 16" Huffy Disney Princess Bike

tjmcd
01-13-2007, 09:51 PM
Or...
Simply replace <input name="product" value="<?php echo $_product;?>" size="100">... with<textarea cols="43"><?php echo $_product;?></textarea></td> in the form. no value="... duhhhh...problem solved:p
Or... better still, use htmlentities() http://us3.php.net/manual/en/function.htmlentities.php
<input name="product" value="<?php echo htmlentities($_product, ENT_QUOTES);?>" size="100">
Thanks though NightShift, I do appreciate the speedy reply.