Check if value exists before inserting into MySQL DB in PHP script

I searched for similar questions without success.

I have this piece of code:

form1.php

$query = "INSERT INTO table1 "; $query .= "(fname, lname, mail)"; $query .= " VALUES "; $query .= "('".$_POST[fname]."', '".$_POST[lname]."', '".$_POST[mail]."')"; $result = mysql_query($query) or die ("Query Failed: " . mysql_error()); 

And I want the script to check if a value is inserted in the corresponding column, and throw an error if that happens. any ideas?

+4
source share
1 answer

Create a UNIQUE key in the areas of interest to you and discover an integrity error after the fact.

+10
source

All Articles