[nycphp-talk] MySQL and spaces in data
Jeff
jsiegel1 at optonline.net
Fri Jun 20 07:56:34 EDT 2003
Adam,
I was mistaken about htmlentities...I believe it's html_entity_decode
that doesn't exist in 4.1.
And your "guess" on how it is being done is right on the mark. Quite
honestly, I hadn't thought about just setting the value to the model
(instead of '1').
You offered some great ideas...I'm going to revisit the code and, if
time permits, go with the suggestion of input name as array with a value
= the model.
Thanks so much for putting in the effort to help straighten this out
(and thanks go to everyone else who offered suggestions).
Jeff
P.S. I may have failed to mention that I started using PHP about 5
months ago...when I started this project...so I'm always learning
something new.
-----Original Message-----
From: Adam Maccabee Trachtenberg [mailto:adam at trachtenberg.com]
Sent: Friday, June 20, 2003 12:37 AM
To: NYPHP Talk
Subject: RE: [nycphp-talk] MySQL and spaces in data
On Thu, 19 Jun 2003, Jeff wrote:
> To differentiate makes/models on the page I generate checkboxes that
> look like the following:
>
> <input name="ALFA-ROMEO|GTV-6" type="checkbox" value="1" checked >
> <input name="ALFA-ROMEO|SPIDER VELOCE" type="checkbox" value="1">
>
> First part gives me the manufacturer, second part gives me the model.
Why don't you make the input name an array value like:
"makes[ALFA-ROMEO]" and give it a value of "GTV-6" or "SPIDER VELOCE"?
Then, you can do something like:
foreach ($makes as $make => $model) {
print "Dealer has an $make $model";
}
Right now, you're probably doing something like:
foreach ($_POST as $data) {
$clean = str_replace($data, "_", "-");
list($make, $model) = split($clean, "|");
print "Dealer has a $make $model";
}
(I may have some function parameter orders mixed up here.)
Since the browser only sends back "checked" checkboxes to the server,
what's the point of setting a value of "1"? Things should be easier if
you set the value to an actually useful value, like say, the model, or
even the make and the model. Then, at least, you wouldn't need to
worry about the weird re-encoding of the data and the restriction on
spaces.
> Keep in mind that I'm on php 4.1.x and it does not have htmlentities
nor
> html_decode_entity.
FWIW, htmlentities() has been around forever, so it should be in
4.1. Besides, that's pretty easy to mimic with strtr():
$from = array('&', '<', '>', '"');
$to = array('&', '<', '>', '"');
$html = strtr($ascii, $from, $to);
(Well, you may have to rearrange the order to do a double pass because
of the &, but this is a good start.)
-adam
--
adam at trachtenberg.com
author of o'reilly's php cookbook
avoid the holiday rush, buy your copy today!
--- Unsubscribe at http://nyphp.org/list/ ---
More information about the talk
mailing list