I have problem with double links in mydatabase.
I have in php file form for new posts. There is $_POST[‘title’]
When people submit title php creates a new url to database from title. Problem is when users submit title that already exists in db, beacause php created double link. I would like to write a function that checks url and if it exists create another link for new post, for example: if exist /posts/new_link function create another, like: /posts/new_link_1.
I had this code:
$link = $_GET['url'];
$checkdb = mysql_query("SELECT `url` FROM `posts` WHERE `url`='$link'" ) or die("ERROR");
$howmanypost = mysql_num_rows($checkdb); //this is check links in db
if ($howmanypost = $newlinksfromtitle) {
// Here I would like the function that creates a new url to db
} else {
$newpost = "INSERT INTO `posts` (`id`, `title`, `img`, `tags`, `author`, `data`, `type`, `url`) VALUES ('', '$title', '$img', '$tags', '$author', '$data', 'img', '$url')";
$makepost = mysql_query($newpost);
}
Sorry for my bad english.
If you know that all the posts with the same title have similar URLs, query for that:
Make sure that you’re properly sanitizing your inputs so your strings are not subject to SQL injection.