Ingenious Posted February 12, 2012 Share Posted February 12, 2012 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> "; } Quote Link to comment https://forums.phpfreaks.com/topic/256977-db-returns-truncated-values-when-hit-a-spaces/ Share on other sites More sharing options...
kicken Posted February 13, 2012 Share Posted February 13, 2012 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 />" Quote Link to comment https://forums.phpfreaks.com/topic/256977-db-returns-truncated-values-when-hit-a-spaces/#findComment-1317616 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.