I currently have a html form submitting data to my database. The user submits a name and a url with it and it gets stored into my table. What I am trying to achieve is when the user enters a name into the text field along with a url in the url field I want to search my database to see if there is a entry with that name already. If so I want it to not add the entry to the database.
This is what I currently have set up to submit the current data entered into the database.
$title=$_POST['title'];
$url=$_POST['url'];
$query = "INSERT INTO images VALUES ('$title','$url')";
mysql_query($query) or die('Error, insert query failed');
I am still fairly new to PHP so any help on how I can achieve this would be greatly appreciated! Thanks! 🙂
If you set title in database as
unique, you can use:This will insert a new row and if that particular title already exists in database update its url.