Reply to Re: $_POST adding whitespace to variable value

Your name:

Reply:


Posted by Rik Wasmus on 11/12/04 12:00

On Tue, 15 Jan 2008 17:28:59 +0100, Mason Barge <masonbarge@comcast.net>=
=

wrote:
> My problem is that the information transmitted to the formhandler =

> apparently has some sort of whitespace added to it. If I simply use =

> trim() on the POST variable, it fails the regex. If I convert to POST=
=

> variable to a single variable and use trim(), it solves the problem.
>
> This code throws a regex rejection:
>
> $_POST['zip']=3Dtrim($_POST['zip']);
> if (preg_match("/^[\d]{5}/", $_Post['zip'])) {

$_Post !=3D $_Post
As soon as you've fixed that, this would work, but it is not =

recommendable. Having a clear view of what your user actually submitted,=
=

and how you've handled/altered the data after that will save you lots of=
=

debugging time.

And just on a side note: shouldn't it be "/^[\d]{5}$/" ? The regex now =

will consider '12345and then some arbitrary text or characters' valid...=


> SECONDARY PROBLEM
>
> Of course, my real problem is how the whitespace gets in there in the =
=

> first place. Or more accurately, why the regex would reject informati=
on =

> from the database. In the case of "$zip", the field is VARCHAR(5).
>
> Here's the form entry:
> <input type=3D"text" name=3D"zip" size=3D"5" maxlength=3D"5" =
=

> value=3D"<?php if(isset($_POST['submit'])) {
> echo $_POST['zip'];
> } else {
> echo $zip;
> } ?>
> " />

Here is is. You have whitespace between '?>' and '" />', which will =

probably translate itself to a space in the field in HTML context.
Use:' } ?>" />'

-- =

Rik Wasmus

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация