Smudly Posted June 8, 2010 Share Posted June 8, 2010 Users on my website are able to submit a website. I need to create a check that ensures that website has not already been added by the current user (It does not matter if any other user adds the same website). So for example, I need to check if the url they have submitted is equal to a url in the database that has the userid of that user. Hope I am making sense Here is a bit of pseudocode to kind of explain better what I mean: if $url == for userid $userid: echo "That site has already been submitted" thanks Quote Link to comment https://forums.phpfreaks.com/topic/204224-checking-for-duplicates-in-table-for-current-user/ Share on other sites More sharing options...
kratsg Posted June 8, 2010 Share Posted June 8, 2010 "SELECT [fields] WHERE userid = $userid AND url = $url"; Users on my website are able to submit a website. I need to create a check that ensures that website has not already been added by the current user (It does not matter if any other user adds the same website). So for example, I need to check if the url they have submitted is equal to a url in the database that has the userid of that user. Hope I am making sense Here is a bit of pseudocode to kind of explain better what I mean: if $url == for userid $userid: echo "That site has already been submitted" thanks Quote Link to comment https://forums.phpfreaks.com/topic/204224-checking-for-duplicates-in-table-for-current-user/#findComment-1069639 Share on other sites More sharing options...
Smudly Posted June 8, 2010 Author Share Posted June 8, 2010 I am getting this error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource The code I have is: //Check if URL is a Duplicate for current user $urlcheck = mysql_query("SELECT `url` FROM `websites` WHERE `userid` = $userid AND `url` = $url"); $urlcount = mysql_num_rows($urlcheck); if ($urlcount==0) { echo "Your Site Has Been Submitted"; $query2 = mysql_query("INSERT INTO websites VALUES ('','$userid','$url','$credits','','','','$title')"); } else{ echo "You have already submitted that site"; } I tried typing in: if (!$result = mysql_query($query)) { die(mysql_error()); } $num_result = mysql_num_rows($result); and it states that "Query was empty" Quote Link to comment https://forums.phpfreaks.com/topic/204224-checking-for-duplicates-in-table-for-current-user/#findComment-1069647 Share on other sites More sharing options...
ignace Posted June 8, 2010 Share Posted June 8, 2010 It should be SELECT `url` FROM `websites` WHERE `userid` = '$userid' AND `url` = '$url' Quote Link to comment https://forums.phpfreaks.com/topic/204224-checking-for-duplicates-in-table-for-current-user/#findComment-1069655 Share on other sites More sharing options...
Smudly Posted June 8, 2010 Author Share Posted June 8, 2010 Thanks, that worked. Quote Link to comment https://forums.phpfreaks.com/topic/204224-checking-for-duplicates-in-table-for-current-user/#findComment-1069659 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.