Jump to content

Checking for duplicates in table for current user


Smudly

Recommended Posts

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

"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

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"

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.