frozenskydiver Posted April 26, 2010 Share Posted April 26, 2010 Hi. Im making a gaming competitive site. Anyway in profile section I have it where they can add their ids. I wanted a code to prevent people from adding same id as someone elses.Ive used code below } if(mysql_num_rows(mysql_query("SELECT id FROM members WHERE icq='$member[icq]'"))){ $mes.="Cod5 id is already in use.<br />"; } This code works for what i want however if you go into ur profile and dont edit anything or edit a completely different id and click update account it picks up that the cod5 id is already in use even though you did not change it and no one but you have it. The code is reading its own users id so it thinks your adding a duplicate id. What do i need to add to that code to have it check all ids except your own(user logged in at the time)? Thanks a lot for all your help.. Im new to php. Quote Link to comment Share on other sites More sharing options...
DavidAM Posted April 27, 2010 Share Posted April 27, 2010 add AND id != $userid in place of $userid put whatever variable you have the current user's id stored in. Quote Link to comment Share on other sites More sharing options...
frozenskydiver Posted April 28, 2010 Author Share Posted April 28, 2010 ok so code would be... } if(mysql_num_rows(mysql_query("SELECT id FROM members WHERE icq='$member[icq]' AND id != $userid"))){ $mes.="Cod5 id is already in use.<br />"; } ?? But the id for current user would be different depending on whos logged into my site at the time.So would this still work?? Quote Link to comment Share on other sites More sharing options...
DavidAM Posted April 29, 2010 Share Posted April 29, 2010 replace $userid with whatever variable holds the id of the user that is currently logged in. This tells the query not to look at the current user's record, we expect the icq to match on that record and we don't care that it does because it is the same record we are about to update. Quote Link to comment Share on other sites More sharing options...
frozenskydiver Posted June 3, 2010 Author Share Posted June 3, 2010 david this script works great.Only problem I have now is theres bout 5 ids someone can enter.if they enter one id and leave the other blank it picks up that other users also have a blank id and says its duplicate id.Anyway to fix this? Thanks Quote Link to comment 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.