jmalouff Posted March 2, 2009 Share Posted March 2, 2009 I am working on a basic PHP Form that when submitted does a quick error check. All Works Well in my development environment. However when form is on the live server all does as it is supposed to but when doing the error checking one of the forms request the end user to enter a Affiliate code of their choice! I want these to be unique! so if a user enters one that was already entered previously it attempts to query the database for an duplicate. this way i can make sure that each Code entered is unique. However online it submits with out giving an error and it allows duplicates to enter the database. In my development environment when i submit the form with the same file it errors out saying that the Here is my code. /* Begin Unique Affiliate Code Check */ $sql = "SELECT * FROM affiliates WHERE affiliate_code='".$affiliate_code."'"; $res = mysql_query($sql) or die (mysql_error()); if (mysql_num_rows ($res) > 0) { $curnum ++; echo "<tr><td>".$curnum.". The Affiliate Code ' <b>".$affiliate_code."</b> ' already exists </tr></td>"; } /* End Unique Affiliate Code Check */ am i doing something wrong? any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/147589-solved-help-unique-form-validation/ Share on other sites More sharing options...
premiso Posted March 2, 2009 Share Posted March 2, 2009 If you can, modify that field in the table to be "UNIQUE" this will prevent duplicates from being entered at the SQL level. As far as why that is not returning the affiliates like it should, try trim ing the data and check if Magic Quotes are enabled on the production server, as that may be escaping data. If it is I would suggest turning them off or using get_magic_quotes_gpc to test if it is on if it is, do a stripslashes on the data. Quote Link to comment https://forums.phpfreaks.com/topic/147589-solved-help-unique-form-validation/#findComment-774810 Share on other sites More sharing options...
jmalouff Posted March 2, 2009 Author Share Posted March 2, 2009 Thanks for your help! Here is what i found in RE: to my php.ini (Magic Quotes) - Is this the right area? ; Magic quotes ; ; Magic quotes for incoming GET/POST/Cookie data. magic_quotes_gpc = On ; Magic quotes for runtime-generated data, e.g. data from SQL, from exec(), etc. magic_quotes_runtime = Off Quote Link to comment https://forums.phpfreaks.com/topic/147589-solved-help-unique-form-validation/#findComment-774818 Share on other sites More sharing options...
premiso Posted March 2, 2009 Share Posted March 2, 2009 Yes, you should set both to Off. For data going into the DB (textual data) you should use mysql_real_escape_string to escape it instead. Quote Link to comment https://forums.phpfreaks.com/topic/147589-solved-help-unique-form-validation/#findComment-774831 Share on other sites More sharing options...
jmalouff Posted March 2, 2009 Author Share Posted March 2, 2009 turning the magic Codes to OFF in the php.ini file HELPED and FIXED the problem! Thanks for your help! ;D Quote Link to comment https://forums.phpfreaks.com/topic/147589-solved-help-unique-form-validation/#findComment-774866 Share on other sites More sharing options...
Psycho Posted March 2, 2009 Share Posted March 2, 2009 Please mark thread as solved! Also, I wouldsuggest changing your query as follows $sql = "SELECT affiliate_code FROM affiliates WHERE affiliate_code='".$affiliate_code."'"; No need to query all fields in the table. Quote Link to comment https://forums.phpfreaks.com/topic/147589-solved-help-unique-form-validation/#findComment-774869 Share on other sites More sharing options...
jmalouff Posted March 2, 2009 Author Share Posted March 2, 2009 thanks for the suggestions.. It makes sense & ill make the update!!.. I'm sorry.. but i am not sure how to mark it as resolved? Quote Link to comment https://forums.phpfreaks.com/topic/147589-solved-help-unique-form-validation/#findComment-774878 Share on other sites More sharing options...
premiso Posted March 2, 2009 Share Posted March 2, 2009 Bottom left hand corner above Quick Reply, "Topic Solved" Quote Link to comment https://forums.phpfreaks.com/topic/147589-solved-help-unique-form-validation/#findComment-774879 Share on other sites More sharing options...
jmalouff Posted March 2, 2009 Author Share Posted March 2, 2009 How hard it is to have an email sent to the user confirming their registration? or at least.. Send a letter to me letting me know someone submitted the form.. Thanks in advance!! Quote Link to comment https://forums.phpfreaks.com/topic/147589-solved-help-unique-form-validation/#findComment-774896 Share on other sites More sharing options...
premiso Posted March 2, 2009 Share Posted March 2, 2009 mail Not hard at all, given you have a mail server to use. Quote Link to comment https://forums.phpfreaks.com/topic/147589-solved-help-unique-form-validation/#findComment-774934 Share on other sites More sharing options...
jmalouff Posted March 2, 2009 Author Share Posted March 2, 2009 I do.. The form is sitting on a dedicated server. what would i need to add to the code to make it do it? I'm sorry for all the questions!! Quote Link to comment https://forums.phpfreaks.com/topic/147589-solved-help-unique-form-validation/#findComment-774962 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.