amankaurm Posted December 1, 2012 Share Posted December 1, 2012 hello I am faceing one problem in my project. Data entered by user here UserId is unique auto increment by code ************************ UserId Name Time 12LAB00019 Vijay 24Nov 2012 02:11:34PM 12LAB00019 Vijay 24Nov 2012 02:11:34PM one user get same UserId in database table it store as UID - This is auto increment UID UserId Name Time 18 12LAB00019 Vijay 24Nov 2012 02:11:34PM 19 12LAB00019 Vijay 24Nov 2012 02:11:34PM Double Record entered in Database ***************************** This is another big problem that one user entered so many time from 5234 to 5248 all ids are taken by this user UserId Name Time 12LAB05234 Jay Kumar 30Nov 2012 5:00:25PM 12LAB05234 Jay Kumar 30Nov 2012 5:00:25PM 12LAB05237 Jay Kumar 30Nov 2012 5:00:26PM 12LAB05237 Jay Kumar 30Nov 2012 5:00:26PM 12LAB05237 Jay Kumar 30Nov 2012 5:00:26PM 12LAB05239 Jay Kumar 30Nov 2012 5:00:27PM 12LAB05239 Jay Kumar 30Nov 2012 5:00:27PM 12LAB05242 Jay Kumar 30Nov 2012 5:00:28PM 12LAB05242 Jay Kumar 30Nov 2012 5:00:28PM 12LAB05242 Jay Kumar 30Nov 2012 5:00:28PM 12LAB05244 Jay Kumar 30Nov 2012 5:00:29PM 12LAB05244 Jay Kumar 30Nov 2012 5:00:29PM 12LAB05246 Jay Kumar 30Nov 2012 5:00:32PM 12LAB05246 Jay Kumar 30Nov 2012 5:00:32PM 12LAB05248 Jay Kumar 30Nov 2012 5:00:33PM 12LAB05248 Jay Kumar 30Nov 2012 5:00:33PM In Admin section this data is coming in such a way ... please suggest me solution Quote Link to comment https://forums.phpfreaks.com/topic/271437-duplicate-record-enter-in-db-table/ Share on other sites More sharing options...
floridaflatlander Posted December 1, 2012 Share Posted December 1, 2012 (edited) I don't understand what this is "UID - This is auto increment UID UserId Name Time" Anyway, I usually run a query and if a certain value is already present in a column or in a column with a user id of xx I wont enter the data. Also if you verify your data and your form wont process with out the info being filled out you maybe able to reset a value to false after the info is entered. Then it wont be entered again. Edited December 1, 2012 by floridaflatlander Quote Link to comment https://forums.phpfreaks.com/topic/271437-duplicate-record-enter-in-db-table/#findComment-1396639 Share on other sites More sharing options...
amankaurm Posted December 1, 2012 Author Share Posted December 1, 2012 actually problem comes here in this function coz earlier all conditions ar checked then data come here in this function to insert in database. here i enter data in 2 tables.... function addOnlineUser(......){ mysql_query('LOCK TABLES user'); mysql_query('LOCK TABLES usereducation'); Sql = "INSERT.......user....." $uid = mysql_insert_id(); Sql = "INSERT.......usereducation... .." .........so and so....... $UserId = $this->AutoUserId($PostApply,$uid); mysql_query('UNLOCK TABLES'); //function END user_id field is auto increment and primary key.....and UserId field is made like(12LAB00025 .. 12 is Year , LAB is Post, 000025 is serial number). see in my previous post user_id UserId Name Time 18 12LAB00019 Vijay 24Nov 2012 02:11:34PM 19 12LAB00019 Vijay 24Nov 2012 02:11:34PM Double Record entered in Database here i generate UserId - $uid = mysql_insert_id(); $UserId = $this->AutoUserId($PostApply,$uid); Quote Link to comment https://forums.phpfreaks.com/topic/271437-duplicate-record-enter-in-db-table/#findComment-1396655 Share on other sites More sharing options...
amankaurm Posted December 4, 2012 Author Share Posted December 4, 2012 Here is PHP Code where data is inserted in database function addOnlineUser($PostApply,$name,$fathername,$email,$dob,$Uniq_Id,$age_on_year,$age_on_month,$age_on_day, $ImgVal, $subBoard, $subPassYear, $subHigherQ , $Exservice,$Ex_Served, $Ex_yr, $Ex_mon, $Ex_day, $Designation, $PwdPc, $HHOH, $disability, $OrgCat, $subDDVal, $subDDIPO_NO, $subDDIPO_Date, $subDDIPO_Amount,$subDDIPO_Branch, $Lang,$Nation,$subNationOthers, $subPermanentAddLine1, $subPermanentAddLine2,$subPermanentCity, $subPermanentState,$subPermanentPincode, $subPresentAddLine1, $subPresentAddLine2,$subPresentCity, $subPresentState,$subPresentPincode, $subCity, $subDistrict, $subState, $subCommunity , $subStation, $TodayDate ){ date_default_timezone_set('Asia/Calcutta'); $DateTime = date('l jS \of F Y h:i:s A'); mysql_query('LOCK TABLES user'); mysql_query('LOCK TABLES usereducation'); $UserId = $Uniq_Id; $q = "INSERT INTO ".TBL_USER."(UserId,postapply,name,fathername,email,dob,uniq_Id,age_on_year,age_on_month,age_on_day,imgval, exserviceman,ex_Served,ex_yr,ex_mon,ex_day,ex_Designation,pwdpc,hhoh,pwdpc_disability,org_cat, dd_ipo,ddipo_NO,ddipo_Date,ddipo_Amount,ddipo_Branch, lang_id,nation_id,nationothers, station,TodayDate ) VALUES ('$UserId','$PostApply','$name', '$fathername', '$email','$dob','$Uniq_Id',$age_on_year,$age_on_month,$age_on_day,'$ImgVal', $Exservice,'$Ex_Served',$Ex_yr,$Ex_mon,$Ex_day,'$Designation',$PwdPc,$HHOH,'$disability',$OrgCat, '$subDDVal','$subDDIPO_NO','$subDDIPO_Date',$subDDIPO_Amount,'$subDDIPO_Branch', $Lang,$Nation,'$subNationOthers', '$subStation', '$TodayDate' )"; $result = mysql_query($q, $this->connection); $uid = mysql_insert_id(); $p = "INSERT INTO ".TBL_USEREDUCATION."(user_uniqid, board, board_passyr, HigherQ , PermanentAddLine1, PermanentAddLine2, PermanentCity, PermanentState, PermanentPincode, PresentAddLine1, PresentAddLine2, PresentCity, PresentState, PresentPincode, Time, city, district, state, community ) VALUES ('$Uniq_Id','$subBoard',$subPassYear, '$subHigherQ' , '$subPermanentAddLine1', '$subPermanentAddLine2','$subPermanentCity', '$subPermanentState',$subPermanentPincode, '$subPresentAddLine1', '$subPresentAddLine2','$subPresentCity', '$subPresentState',$subPresentPincode, '$DateTime', '$subCity', '$subDistrict', '$subState', '$subCommunity' )"; $resultP = mysql_query($p, $this->connection); $UserId = $this->AutoUserId($PostApply,$uid); $up_id = "UPDATE ".TBL_USER." SET UserId = '$UserId' WHERE Uniq_Id = '$Uniq_Id'"; mysql_query($up_id, $this->connection); /* Error occurred, return given name by default */ if(!$result){ $Delq = "DELETE FROM ".TBL_USEREDUCATION." WHERE user_uniqid = '$Uniq_Id'"; mysql_query($Delq, $this->connection); } if(!$resultP){ $DelP = "DELETE FROM ".TBL_USER." WHERE uniq_Id = '$Uniq_Id'"; mysql_query($DelP, $this->connection); } mysql_query('UNLOCK TABLES'); if(!$result || !$resultP){ return NULL; } return $result; } Quote Link to comment https://forums.phpfreaks.com/topic/271437-duplicate-record-enter-in-db-table/#findComment-1397431 Share on other sites More sharing options...
Christian F. Posted December 4, 2012 Share Posted December 4, 2012 Please use the [code][/code] tags around your code, as it helps make both your post and your code a lot easier to read. Quote Link to comment https://forums.phpfreaks.com/topic/271437-duplicate-record-enter-in-db-table/#findComment-1397449 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.