I'm trying to figure out a way to get this if statement to work..

$array = $_POST['field'];
foreach ($array as $key => $value) {
	if ($value does not exist in database) {
		$query  = "INSERT INTO..."; 
	elseif ($value >= 1) {
		$query  = "UPDATE... "; 
	} else {
		$query  = "DELETE FROM... "; 
	}
}

The part I cannot figure out is the first part of the if statement, if the value does not exist in the database.. Is there some way to check if that value exists so it knows whether to insert or update?

you can use triggers to update only after any insert has been done...

or simply use:

$query = "SELECT * FROM users WHERE name='$name';";
$res = mysql_query($query);
if (mysql_num_rows($res) > 0) {
// yes, pull in the user details
} else
// no, user doesn't exist
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.