I am trying to make a script to save image link in database like example.com/image.jpg
every thing is working fine I just want that if someone enter wrong url like without extension .jpg , .png or .gif
it give error to user so they enter correct url
Here is my Php Code
if(isset($_POST['img']));
$img = $_POST['img'];
$ti = $_POST['titl'];
$query = mysqli_query($con,"SELECT * FROM image WHERE url='$img'")
or die(mysqli_error($con));
if(mysqli_num_rows($query) > 0 ) { //check if there is already an entry for that word
echo "Image already exists! ";
}
else {
mysqli_query($con,"INSERT INTO image (Title, url,) VALUES ('$ti','$img')");
echo "Image Successfully Added";
}
And here is html
<form action="" method="POST" >
<span>Title:</span>
<input type="text" name="titl" maxlength="100" /><br>
<span>Image URL:</span>
<input type="text" name="img" maxlength="300" />
<input type="submit" value="Add Image!" id="subm" class="button" />
</form>