Re: php Form Validation help

From: Date: Mon, 06 Sep 2004 23:39:49 +0000
Subject: Re: php Form Validation help
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-36080@lists.php.net to get a copy of this message
See below for point-by-point. ... > > <CODE> > > $state = $_POST['state']; > > if ($state = 0) { = is an assignment operator. This will always test true, because $state is set to 0 every time this is called. You want ==, which is a comparison operator. > print '<p>Please select your State</p>'; > > } > > </CODE> > .... > <CODE> > > $phone = $_POST['p-areacode'] . - . $_POST['p-prefix']. - . > $_POST['p-suffix']; > > </CODE> More like: $phone = $_[PST[area] . "-" ...... You get the idea -- dashes need to be surrounded by quotes. > > The next question id for both phone number and area code. > > > > If I want to validate the zip code and ensure a minimum of X characters in > the field, numbers only how would I do this? You can check the string length and see if it's within the bounds you want. Look at the Strings section of the PHP manual for the proper function (str_len, I think). > > Would this be somewhat on the right track? > > <CODE> > > If ($zip str >5) { > > print '<p>Please enter your Zip Code (EX. 77662)</p>'; > > } > > </CODE> Nope. If someone entered 98115, then this would be > 5, since there's a difference of 98110 integers :) > > And for the phone number I would assume I could use: > > <CODE> > > If ($_POST['p-areacode'] str >3 ) { > > print '<p>Please enter your Area Code (EX. 77662)</p>'; > > } > > </CODE> > See comment on string length above. > > > I am still new with PHP, any help would be appreciated. Below is the code I > have sofar: > > Hope this helps. -- Peter Ellis - pellis@naturalaxis.com Web Design and Development Consultant naturalaxis | http://www.naturalaxis.com/

« previous php.db (#36080) next »