Spaces becoming underlines

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I have two example strings, a name - 'SMITHJ' - and a short phrase -
'Town and Country' - which together uniquely identify a record on my
database. I concatenate them with a separating '&' to create a single
string identifier for the record - 'SMITHJ&Town and Country'.

I create a Form for my user, each line containing some identifying data
from a different database record, and a 'Submit' button (labelled
'Edit') named by an identifier as created above.

When the Form is processed, I determine which record the user wishes to
edit by checking the name of the pressed 'Edit' button.

When I 'explode' this name to its two constituent parts, I discover that
somewhere along the above process, 'Town and Country' has become
'Town_and_Country'. (I am using PHP5.)

Where and why has this happened?

Should I be prepared for any further character substitutions?

Re: Spaces becoming underlines

Alan M Dunsmuir escribió:
Quoted text here. Click to load it

No code at all so I'll have to guess. You take database output and use
it as value for the name attribute in an input element:

<input name="<?=htmlspecialchars($foo)?>" ... >

Your DB contents are unrestricted (beyond field size) but the name
attribute is not:

"# ID and NAME tokens must begin with a letter ([A-Za-z]) and may be
followed by any number of letters, digits ([0-9]), hyphens ("-"),
underscores ("_"), colons (":"), and periods (".")."

Than means you can expect all sort of data loss whenever your DB fields
have something that is not in the above list.

Without making big changes, I may suggest:

<input name="record_id" value="<?=htmlspecialchars($foo)?>" ... >

This should work if there aren't tabs or line feeds in your data.

-- - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web:
-- Mi web de humor al baño María:

Re: Spaces becoming underlines

On Mon, 21 Apr 2008 06:11:31 +0200, Alan M Dunsmuir  =

Quoted text here. Click to load it

Quoted text here. Click to load it

Quoted text here. Click to load it

Quoted text here. Click to load it

Quoted text here. Click to load it

Thank the evil that is register_globals. Because of this feature, all  =

names in form fields are 'transposed' to a valid variable name in PHP.  =

Which is why for instance in input type=3D"image" yields the <name of  =

input>_x & <name of input>_y in PHP, while the client actually sends <name  =

of input>.x and <name of input>.y

Quoted text here. Click to load it

Yes, unfortunately. All characters not valid in a PHP variable name will=

probably by substituted.
-- =

Rik Wasmus

Re: Spaces becoming underlines

Alan M Dunsmuir wrote:
Quoted text here. Click to load it

Yep, as others have indicated, it's the name of the edit button that's
doing it.

It would have been better if you had submitted some code, it would be
easier.  But I suspect you have one form with multiple edit buttons,
each edit button being identified by its respective record id.

One way to solve this would be to have separate forms for each entry,
each with a hidden field for the id and its own submit button.  Another
one could have a single form with a single hidden field; when the user
clicks on the edit button, the hidden field is filled in with the
appropriate value through javascript, but this does require javascript
be enabled.

Probably the best way, IMHO, would be to redo your primary key on your
data.  Rather than make it related to the data like you do have (a very
bad idea), have an independent field, i.e. an automatically incrementing
integer column.  Then have the edit buttons with names such as edit_54,
edit_77, etc., where 54 and 77 would be the id's of your rows.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Site Timeline