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
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.
Orio, dude, You rule!

Thanks very much for that. Like I said, the solution is so simple - especially when you explain it aswell.

This learning curve is steep - but its great fun, and forums like this are invaluable.

Thanks again man.

Nick.

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.