Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: form validation
05-29-2008, 08:15 PM #1
- Join Date
- Sep 2007
- Thanked 0 Times in 0 Posts
i need to validate a field in a form where a user enters a reference number this can be
letters, numbers and special characters also so i have not written any special preg match as
the username is a combination. the only check i am doing is if there are any white spaces
and if a user simple presses the space bar and does not enter value i display a message to
enter the reference number and even if there are white spaces followed by the reference
number i have used trim method. i have checked in the database even if there are white
spaces followed by reference number due to trim() method the data in the table is being
inserted whithout those white spaces.
following is the code i am presently using
$referencenumber = trim($_POST["referencenumber"]);
if(strlen($referencenumber) == 0)
$error.="<li>Reference number cannot be blank </li> <br />";
techniques to avoid sql injection. following is the technique i have used
$username = stripslashes($_POST["username"]);
$username = $_POST["username"];
$lodgementnumber = stripslashes($_POST["lodgementnumber"]);
$lodgementnumber = trim($_POST["lodgementnumber"]);
if(strlen($lodgementnumber) == 0)
$error.="reference number cannot be blank;
i need to use techniques to avoid sql injection and i also need the validation to work.
how can i fix this.
Last edited by Inigoesdr; 05-30-2008 at 07:22 AM.
05-29-2008, 08:30 PM #2
- Join Date
- May 2008
- Thanked 21 Times in 21 Posts
I'll be the first to say it: use php tags when posting code! Furthermore, use punctuation when posting anything else. If English is not your first language, I apologize for my previous comment - it can be very difficult to describe computer problems in another language.
Anyway, I use mysql_real_escape_string() to make variables safe for SQL.