Jump to content


Photo

Populating form fields from MySQL when data contains spaces


  • Please log in to reply
2 replies to this topic

#1 nickholt1972

nickholt1972
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts
  • LocationBury, Lancs, UK

Posted 06 August 2006 - 08:55 AM

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 after the first space 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 echo $description 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 "This".

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

Thanks,

Nick
Nick Holt - Future Guru

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 06 August 2006 - 09:00 AM

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="<?php echo $description; ?>" />
(Notice the qoutes around the value of "value")

Orio.
Think you're smarty?

(Gone until 20 to November)

#3 nickholt1972

nickholt1972
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts
  • LocationBury, Lancs, UK

Posted 06 August 2006 - 09:15 AM

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.
Nick Holt - Future Guru




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users