I have an array of items that I am looping over and checking if the value already exists in the database, if it does I would like to update it, if it does not I would like to create a new entry. The first item in the array is seen and returns true, but anything after the first one returns 0 even if I know for a fact that it is in the database with the correct item_name and ticket_id.
I have tried researching before asking, but am stumped at this point. Thanks for any help in advance.
if($func == 'edit') {
foreach ($addItem as $key => $value) {
if (empty($key) || $key=='amount_paid') {
continue;
}
$ticket_items = mysql_query("SELECT * FROM ticket_items WHERE ticket_id = '$ticket_id' AND item_name = '$key'");
if (mysql_num_rows($ticket_items)) {
print 'Updated '. $key ."
";
mysql_query("UPDATE ticket_items set item_name='$key', item_price='$value' WHERE ticket_id='$ticket_id'");
} else {
print 'Created '. $key ."
";
mysql_query("INSERT into ticket_items (ticket_id, item_name, item_price) VALUES ('$ticket_id', '$key', '$value')");
}
}
}