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? Link to comment https://forums.phpfreaks.com/topic/197137-checking-if-url-exists-in-database/ 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. Link to comment https://forums.phpfreaks.com/topic/197137-checking-if-url-exists-in-database/#findComment-1034805 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. Link to comment https://forums.phpfreaks.com/topic/197137-checking-if-url-exists-in-database/#findComment-1034811 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 Link to comment https://forums.phpfreaks.com/topic/197137-checking-if-url-exists-in-database/#findComment-1034818 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.