Been very frustrating but mysql is returning an empty set for this code (not echoing exists) :
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("repository", $con);
$url = stripslashes($url);
$url = mysql_real_escape_string($url, $con);
$exists = mysql_query("SELECT url FROM sites WHERE url = '$url' LIMIT 1");
if (mysql_num_rows($exists) == 1) {
echo "exists";
}
it should not be doing this because I’ve tested a good amount.
The table consists of one column “url”, it is datatype varchar(1000) (the maximum). the url stored for test purposes is http://en.wikipedia.org/wiki/Thailand
Here’s what you do as a first step. Remove the
WHERE url = '$url'from your query altogether and print outmysql_num_rows($exists)before using it.That should be enough to tell if it’s one of the two likeliest problems:
Based on your comments to date, the former is the most likely. If it turns out you get a row back without the
whereclause, you’ll have to figure out why your URL is incorrect. This may be a case-sensitivity issue or a padding (size) issue, among other things.If, as you mention in a comment,
likeworks where=doesn’t, then we need to see your data.Execute (at the DB level):
and show us exactly what the output is. Similarly, output the URL being used by the code with something like:
immediately before executing the
mysql_query.Please append the output from both those commands to your question.