xwishmasterx Posted March 31, 2010 Share Posted March 31, 2010 Hello I have a directory script where users can submit websites. I need it to check for the input of the urls to avoid duplicates. How can I do this? Quote Link to comment Share on other sites More sharing options...
Jax2 Posted March 31, 2010 Share Posted March 31, 2010 Pretty easy actually... just do an sql statement: $userinputULR=$_REQUEST['url']; "Select * from table where url=$userinputURL" and check to see if any rows are returned using num_rows, and if num_rows result isn't 0, it already exists in your database. Quote Link to comment Share on other sites More sharing options...
the182guy Posted March 31, 2010 Share Posted March 31, 2010 Best practice for this is to use a SELECT COUNT() query like: SELECT COUNT(id) AS num FROM websites WHERE url = '$url' There will be one row returned with just one field called 'num'. Using a normal SELECT or SELECT * is inefficient because you are asking the MySQL server to pull out a dataset which you don't even need, you only want to know how many rows there are. Quote Link to comment Share on other sites More sharing options...
Jax2 Posted March 31, 2010 Share Posted March 31, 2010 Quite true, wasn't thinking straight LOL! 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.