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>
";
}

 

Link to comment
Share on other sites

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 />"

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.