msafvati Posted September 6, 2008 Share Posted September 6, 2008 Hi my friends I have a question! How can I prevent from REPETITIVE ENTRANCEs such as username that we want to don’t repititive in my database Please help me $a=odbc_result($res,'username'); if ($a==$_POST['t9']){ echo "Repititve!!!! in DB"; } Link to comment https://forums.phpfreaks.com/topic/123033-solved-prevent-from-repetitive-entrances-in-db/ Share on other sites More sharing options...
Mchl Posted September 6, 2008 Share Posted September 6, 2008 Set a field as UNIQUE Link to comment https://forums.phpfreaks.com/topic/123033-solved-prevent-from-repetitive-entrances-in-db/#findComment-635291 Share on other sites More sharing options...
BlueSkyIS Posted September 6, 2008 Share Posted September 6, 2008 that will certainly cause an error when you try to insert a duplicate. but to prevent an error, you need to check to see if the record exists first, then warn the user and require them to use a different value. Link to comment https://forums.phpfreaks.com/topic/123033-solved-prevent-from-repetitive-entrances-in-db/#findComment-635296 Share on other sites More sharing options...
Mchl Posted September 6, 2008 Share Posted September 6, 2008 Errors can be parsed, which often will be faster, than executing extra query. Link to comment https://forums.phpfreaks.com/topic/123033-solved-prevent-from-repetitive-entrances-in-db/#findComment-635301 Share on other sites More sharing options...
BlueSkyIS Posted September 6, 2008 Share Posted September 6, 2008 heh. maybe i'll get out a stopwatch and check some day. until then, i'll make sure i'm not trying to insert a duplicate record. Link to comment https://forums.phpfreaks.com/topic/123033-solved-prevent-from-repetitive-entrances-in-db/#findComment-635306 Share on other sites More sharing options...
Mchl Posted September 6, 2008 Share Posted September 6, 2008 Sure. Whatever works better for you. Link to comment https://forums.phpfreaks.com/topic/123033-solved-prevent-from-repetitive-entrances-in-db/#findComment-635321 Share on other sites More sharing options...
msafvati Posted September 6, 2008 Author Share Posted September 6, 2008 thanks but do imposible for u to more guide me? do that suorce is correct? Link to comment https://forums.phpfreaks.com/topic/123033-solved-prevent-from-repetitive-entrances-in-db/#findComment-635335 Share on other sites More sharing options...
ankhmor Posted September 6, 2008 Share Posted September 6, 2008 I can show you how its done in mysql but ur not using mysql are u. Link to comment https://forums.phpfreaks.com/topic/123033-solved-prevent-from-repetitive-entrances-in-db/#findComment-635383 Share on other sites More sharing options...
.josh Posted September 6, 2008 Share Posted September 6, 2008 google for any registration script tutorial and you will find method(s) for checking if there is duplicate data in your db. Link to comment https://forums.phpfreaks.com/topic/123033-solved-prevent-from-repetitive-entrances-in-db/#findComment-635386 Share on other sites More sharing options...
msafvati Posted September 7, 2008 Author Share Posted September 7, 2008 My problem is solved . I write this script and test it and it answer to me. Thanks my friend <?php $conn=odbc_connect("test","",""); $name=$_GET['txt']; $username=$_GET['un']; if (isset($_GET['txt'])){ $qu="select * from tblTest where username like '".$_GET['un']."'"; $res=odbc_do($conn,$qu); $a=odbc_result($res,'username'); if ($a == $_GET['un']){ echo "Duplicate Data"; } else { $query="insert into tblTest(name,username)"."values ('$name','$username')"; $res=odbc_do($conn,$query); if (odbc_num_rows($res) >= 1){ echo "user has benn registered"; } } odbc_close($conn); } ?> Link to comment https://forums.phpfreaks.com/topic/123033-solved-prevent-from-repetitive-entrances-in-db/#findComment-635729 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.