Jump to content

Populating form fields from MySQL when data contains spaces


nickholt1972

Recommended Posts

I'm setting up an online shop and I want to be able to edit the product descriptions. So i've set up an edit form but when I bring the relevant data into my form all the data [b]after the first space [/b] is ignored.

The following is an example of one of the form fields.

<div id="label">
<label>Product Descrition:
</div>
<div id="input">
<input type="text" name="description" size="50" value=<?php echo $description; ?> />
</label>
</div>

I've tried testing [b]echo $description [/b] outside of the form and it displays the data perfectly.

Just to further clarify, the data in the database may read "This is a great Product" but when I display the form for the web administrator to edit the text, it will just say [b]"This"[/b].

Its obviously something very simple - it always is, but i've exhausted all other resources - can anyone help?

Thanks,

Nick
Link to comment
Share on other sites

Let's say $description="one two three". When php echo's this string- this is the output:
<input type="text" name="description" size="50" value=one two three />

When the browser goes over the code he doest understand to what the "two three" part belongs, so he ignores it. The solution will be adding quotes. Change your code to the following:
<input type="text" name="description" size="50" value=[b]"[/b]<?php echo $description; ?>[b]"[/b] />
(Notice the qoutes around the value of "value")

Orio.
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.