473,329 Members | 1,314 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,329 software developers and data experts.

Spaces becoming underlines

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?
Jun 2 '08 #1
3 1122
Alan M Dunsmuir escribió:
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?
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 (".")."

http://www.w3.org/TR/html4/types.html#type-cdata

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.
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
Jun 2 '08 #2
On Mon, 21 Apr 2008 06:11:31 +0200, Alan M Dunsmuir
<al**@moonrake.demon.co.ukwrote:
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?
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="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
Should I be prepared for any further character substitutions?
Yes, unfortunately. All characters not valid in a PHP variable name will
probably by substituted.
--
Rik Wasmus
Jun 2 '08 #3
Alan M Dunsmuir wrote:
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?
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.
js*******@attglobal.net
==================

Jun 2 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: gong | last post by:
hi i recently looked at alexandrescu's book on c++, and i found it pretty much unintelligible. i have a few points which i wonder about. 1. as a developer, it is important, from a bottom line...
1
by: Helge Ruistuen | last post by:
Hello, I'm using SAX parser to read a string of numbers defined as XML list type. Occasionally the 'characters' method is called twice, which means I need a buffer to read the entire string. My...
11
by: SoloCDM | last post by:
What is needed to remove the underline in web page links? Do I need to change the color or is it something in the tag <a>? *********************************************************************...
4
by: John Bowman | last post by:
Hi, I'm not certain this is the best place to post this, but here it goes. I'm trying to get spaces to work correctly when using the WebBrowser control. Basically, I've got a valid XML...
4
by: ITJRW | last post by:
Hi All, I'm going through Microsoft Visual Basic .NET Step by Step Version 2003 by Halvorson. I have performed a Chapter 4 exercise according to the instructions exactly. Using the & character...
3
by: Chris Sharman | last post by:
Are spaces allowed in names ? Eg <input name="my field" type="text" value="my data"> The html4 dtd seems to say this is cdata, which allows embedded single spaces, but say agents may trim...
22
by: rtilley | last post by:
# Spaces are present before and after the XXX filename = ' XXX ' new_filename = filename.strip() if new_filename != filename: print filename Macs allow these spaces in file and folder...
0
by: GiftX | last post by:
Hellow everyone, I am calling/manipulating Excel spreadsheet through VB 6.0. Most of my objectives are accomplished except some cosmetics. Problem#1: For example, after running my program to...
3
by: GiftX | last post by:
Good morning members. I am using VB6 to generate a spreadsheet. My module is working okay but one of my objectives is to print an underline after writing each record in the spreadsheet, just to show...
10
by: JD | last post by:
I've seen websites where the link underline is a different colour to the link text. I've also seen links with dotted underlines (see the hover effect on the 'Change' and 'All Microsoft Sites' links...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.