I want to get the title out of a form and write it to the database. But if the title already exists I want to add number 1 to the title. I can fix that on my own but the problem is how can I (after the 1 is added) check again and if title +1 already exists make it title +2 and so on... Any ideas how I have to construct a while loop that does that?
$title = $_POST["title"];
$sql = "SELECT * FROM [my_table] WHERE title='$title'";
$result = mysqli_query($con, $sql);
if(mysqli_num_rows($result) > 0) {
$title = mysql_real_escape_string($_POST["title"]);
//$title + add 1 to the title
} else {
$title = mysql_real_escape_string($_POST["title"]);
}