Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
can any one help me in solving my problem!

I am using if exits statement to check weather user name , date of birth etc present in the data base or not but i am get the following error

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF EXISTS (select NAME,SUR_NAME,DATE_OF_BIRTH,POST_CODE where NAME='$Name',SUR_N' at line 1



here is my code:

$sql="IF EXISTS (select NAME,SUR_NAME,DATE_OF_BIRTH,POST_CODE where NAME='$Name',SUR_NAME='$SurName',DATE_OF_BIRTH='$Month-$Day-$Year',POST_CODE='$postcode') 
INSERT INTO `user_details`(`REGISTRATION_NUM`, `POST_CODE`, `NAME`, `SUR_NAME`, `FATHER/SPOUSE_NAME`,
 `GENDER`, `DATE_OF_BIRTH`, `QUALIFICATION`, `C_DESIGNATION`, `CONTACT_ADDRESS`, `PERMANENT_ADDRESS`, `CONTACT_NUM`, `ALTERNATE_NUM`, `P_EMAIL`, `ALTERNATE_EMAIL`, `DD_NUM`, `DD_DATE`, `BRANCH/BANK`, `RECENT_PROFILE`, `OBJECTIVE`,
 `ADD_DUTIES`, `ACHIEVEMENTS`, `EXTRA_CIRRICULAR_ACT`, `LANGUAGES`, `INTERESTS_HOBBIES`, `PURPOSE`, `ESSAY`,   `RefName1`, `RefDesgnation1`, `RefAddress1`,
 `RefContactNum1`, `RefBoard1`, `RefName2`, `RefDesignation2`, `RefAddress2`,
 `RefContactNum2`, `RefBoard2`) 
VALUES
 (NULL, '$postcode', '$Name', '$SurName', '$Father_SpouseName',
 '$Gender', '$Month-$Day-$Year', '$Qualification',
 '$CurrentDesignation', '$ConctactAddress', '$PermanentAddress', '$ContactNo', '$AlternativeNo', '$Primary_Email_Id', '$Alternative_Email_Id', '$DDNo', '$DD_Date', '$BankAndBranch',
  '$RecentProfile', '$Objective', '$AdditionalDuties', '$Achievements', '$ExtraCirriculars', '$Languages', '$HobiesInterests', '$Purpose', '$Essay',  '$RefName1', '$RefDesignation1', '$RefAddress1', '$RefContactNo1', '$RefBoard1', '$RefName2', '$RefDesignation2', '$RefAddress2','$RefContactNo2','$RefBoard2')";
Posted
Updated 14-Mar-11 19:36pm
v3

1 solution

1. you may use 'and' in between your various 'where' conditions instead of 'comma (,)'
2. doubt: if so & so data already exists, why to insert once again. better use 'if not exists'.
3. instead of checking various fields "select NAME,SUR_NAME,etc....", use "select top 1 'x'....". this will improve sql performance as well.
4. last suggestion: check for primary keys.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900