I currently use this query to update listings in my database from my php app:
$query = "INSERT INTO listings (title, description) VALUES ('$title','$description')";
This listings table has a ‘postid’ column as it’s primary key that auto increments.
I don’t want to do an INSERT IGNORE and have it check postid. Instead, I’d like to keep the table structure the same and check to see if $title exists.. and not insert if it does.
Will php/mysql allow me to somehow run a:
If ($title does not exist) {
$query = "INSERT INTO listings (title, description) VALUES ('$title','$description')";
}
If so, how would I write that?
You can do the dollowing:
Query your database to see if there is already any list with the given title and if the count query returns 0, execute your insert statement:
But I strongly suggest you to do not manipulate your database this way. Better to use an ORM or a database class instead of putting your SQL statements all over the place.
Good luck.