0

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?

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by Shanti C
0

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
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.