Jump to content

DB returns truncated values when hit a spaces


Ingenious

Recommended Posts

Hi, the problem that I have goes like this. If i do a regular Select query and display it in a table everything is there but if i am filling a input box of a form to use for modifying the values it does not return the entire value:

 

Exemple with the same value

in a table = product_name : Amd Athlon X2

In input field : Amd

 

Here is my code

<?
$sql = "SELECT * FROM tbl_product WHERE product_code = '$_POST[productcode]'";
$result = mysql_query($sql);
if(!$result){
die("Error running $sql:" . mysql_error());
}
?>


<?
while($row = mysql_fetch_array($result))
{
echo "
<form action='functions/moditem.php' method='post'>
<input type='hidden' name='productid' value=". $row['product_id'] .">
Product code : <input type='text' name='productcode' value=". $row['product_code'] ." /><br />
Product Name : <input type='text' name='productname' value=". $row['product_name'] ." /><br />
Product Price: <input type='text' name='productprice' value=". $row['product_price'] ." /><br />
<input type='submit' value='Modify' />
</form>
";
}

 

I'm guessing you figured it out since the thread is marked solved, but for future googlers...

 

The reason is because your not surrounding your attribute values in your HTML in quotes.  For example this:

echo "Product Name : <input type='text' name='productname' value=". $row['product_name'] ." /><br />"

 

will generate the output (given your sample input):

Product Name : <input type='text' name='productname' value=Amd Athlon X2 /><br />

 

When the browser sees that it will use Amd as the value of the attribute, and the Athlon and X2 parts will be considered new attributes (which will simply be ignored as they are invalid).

 

To get the whole string to appear as the value, you have to put it in quotes:

 

Product Name : <input type='text' name='productname' value='Amd Athlon X2' /><br />

 

which means PHP such as:

echo "Product Name : <input type='text' name='productname' value='". $row['product_name'] ."' /><br />"

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.