我在验证 mysql 中的重复条目时遇到了一些问题,而不是返回与已经缩短的记录相关的链接,它创建了一个新记录,知道为什么会发生这种情况吗?这是代码
$url = get_magic_quotes_gpc() ? stripslashes(trim($_REQUEST['cf_url'])) : trim($_REQUEST['cf_url']);
function remove_http($url) {
$disallowed = array('http://', 'https://');
foreach($disallowed as $d) {
if(strpos($url, $d) === 0) {
return str_replace($d, '', $url);
}
}
return $url;
}
$id = rand(10000,99999);
$short = base_convert($id, 20, 36);
$short_url = $short;
$private_url = md5($short);
$result = mysql_query("SELECT * FROM ' . DB_TABLE . ' WHERE original_url = ".mysql_real_escape_string(remove_http($url))."");
$num_rows = mysql_num_rows($result);
if ($num_rows > 0) {
$results = mysql_query("SELECT * FROM ' . DB_TABLE . ' WHERE original_url = ".mysql_real_escape_string(remove_http($url))."");
$object = mysql_fetch_assoc($results);
echo "http://" . BASE_HREF . $object['short_url'];
} else {
mysql_query('LOCK TABLES ' . DB_TABLE . ' WRITE;');
mysql_query('INSERT INTO ' . DB_TABLE . ' (original_url, short_url, private_url, created_on, created_by) VALUES ("' .mysql_real_escape_string(remove_http($url)) . '", "' . $short_url . '", "' . $private_url . '", "' . time() . '", "' . mysql_real_escape_string($_SERVER['REMOTE_ADDR']) . '")');
mysql_query('UNLOCK TABLES');
echo "http://" . BASE_HREF . $short_url;
}
mysql_close();