Varför lyckas jag få kopior i min databas?
Borde inte följande garantera att det inte läggs in två, i detta faller, urls som är lika?
PHP-kod:
$url_id = '';
//Check if URL exist in db
$sql = "SELECT `url_id`, `title` FROM `t_urls` WHERE `url` = '".$url."' LIMIT 1";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
$url_id = $row['url_id'];
$title_from_db = stripslashes($row['title']);
}
//If not, add to db
if($url_id == ''){
$sql = "INSERT INTO `t_urls` (
`url`,
`title`)
VALUES (
'".$url."',
'".mysql_real_escape_string($title)."')";
mysql_query($sql) or die(mysql_error());
}