how to validate this form

I’m rally novice to php and I need your help.
I’m crating a form and my server side scrip is given below. Kindly let me know how to validate it , what are methods I should used to validate, name, contact number and email ?

[php]

<?php //error code. error_reporting(E_ALL^E_NOTICE); $con=mysql_connect('localhost','root',''); mysql_select_db("ydms")or die(mysql_error()); if(isset($_POST['submit'])) { //$cust_id=$_POST[cust_id]; $cust_name=$_POST[cust_name]; $cust_shop_name=$_POST[cust_shop_name]; $cust_add_hnumber=$_POST[cust_add_hnumber]; $cust_add_line1=$_POST[cust_add_line1]; $cust_add_line2=$_POST[cust_add_line2]; $cust_add_city=$_POST[cust_add_city]; $cust_contact_name=$_POST[cust_contact_name]; $cust_contact1=$_POST[cust_contact1]; $cust_contact2=$_POST[cust_contact2]; $route_no=$_POST[route_no]; $state=$_POST[state]; $cust_remark=$_POST[cust_remark]; } // Applying validation rule //cust_id,'$cust_id', $sql=mysql_query ("INSERT INTO customer(cust_name,cust_shop_name,cust_add_hnumber,cust_add_line1,cust_add_line2,cust_add_city,cust_contact_name,cust_contact1,cust_contact2,route_no,state,cust_remark) VALUES('$cust_name','$cust_shop_name','$cust_add_hnumber','$cust_add_line1','$cust_add_line2','$cust_add_city','$cust_contact_name','$cust_contact1','$cust_contact2','$route_no','$state','$cust_remark')")or die(mysql_error()); if($sql){ echo "Successful"; } else { echo "ERROR"; } mysql_close($con); ?>

[/php]

Please Please Please help me

Do you want all the post variables to be necessary???

well , yeah, I’m trying to develop little inventory control system using php and these are the things i’m going to gather for New Customer module. But just let me know how to validate name, contact number and email and that’s enough.

And thank you so much for giving your attention on my question

and how are you trying to validate name, contact number and email??? Are you validating it against the existing record in the DB???

You can validate email address via PHP but validating Names and contact numbers through PHP ???

for name I wanna knw that the user is only entering the letters (not numbers) and for contact number , user must enter 10 digit telephone number and user must enter valid email address using " @" and ". "

Actually I’m also new to PHP :slight_smile: You can use

[php]if(filter_var($email, FILTER_VALIDATE_EMAIL))
{ #code here }
[/php]
to validate email and
[php]if(!(strlen($phone)==10)){
//Error
}[/php]

to validate phone number. But I think to validate name would require use of regular expression and I haven’t touched it yet so can’t give example.

Hope someone else with more experience will give you a detailed answer.

Thank you soooooooo much tanzeelniazi… I’ll try these . thanks again for your kind reply.

Sponsor our Newsletter | Privacy Policy | Terms of Service