Location: PHPKode > projects > Mozart > Mozart-0.0.4/updatecnt.php
<?
// called from: updcontact.php
// description: various updates on CONTACT information (NOTES, ADDRESS, PHONE)
//
include("connect.inc");
include("reqlogin.inc");

// get today's date for _update fields
include("getcurrdate.inc");

// Update Contact table 
$UpdContactSQL = "UPDATE contact SET sal = '$Sal', first = '$FirstName', middle = '$MiddleName', last = '$LastName', bday = '$BirthDate', email='$Email', contact_type = '$CNTType', website = '$URL', month_updated = '$MonthNum', day_updated = '$DayNum', year_updated = '$YearNum', updated_user = '$UserID' WHERE contact_id=$id";
$UpdContact    = mysql_query($UpdContactSQL);
$UpdUserXContSQL = "UPDATE userxcont SET xuser_id = '$ForUser' WHERE xcont_id = '$id' AND xuser_id = '$OldOwner'";
$UpdUserXCont    = mysql_query($UpdUserXContSQL);

// Update notes table
// if note exists then update, otherwise create the note
if ($Information) {
  $ReadNotesSQL = "SELECT * FROM notes WHERE type = 'Contact' AND fk_key = '$id'";
  $ReadNotes   = mysql_query($ReadNotesSQL);
  if ($readnotes = mysql_fetch_array($ReadNotes)) {
	$UpdNotesSQL = "UPDATE notes SET information = '$Information' WHERE type = 'Contact' AND fk_key = '$id'";
	$UpdNotes    = mysql_query($UpdNotesSQL);
  }
  else {
	$InsNotesSQL = "INSERT INTO notes SET information = '$Information', type = 'Contact', fk_key = '$id'";
	$InsNotes    = mysql_query($InsNotesSQL);
  }
}

// Update Address table 
$x = 1;
while ($x <= $addresses) {
   if ($AddrType[$x] == "Delete Address") {
	$UpdAddressSQL = "DELETE FROM address WHERE fk_contact_id = $id AND address_id = $addrkey[$x]";
   }
   else { 
	$UpdAddressSQL = "UPDATE address SET address_type = '$AddrType[$x]', street01 = '$Street01[$x]', street02 = '$Street02[$x]', city = '$City[$x]', state = '$State[$x]', zip = '$Zip[$x]' WHERE fk_contact_id = $id and address_id = $addrkey[$x]";
   }
	$UpdAddress = mysql_query($UpdAddressSQL); 

   if ($AddrType[$x] == "Delete Phone") {
	$UpdPhoneSQL = "DELETE FROM phone WHERE fk_contact_id=$id AND fk_address_id=$addrkey[$x] AND phone_id=$phonekey[$x]";
   }
   elseif ($AddrType[$x] == "Delete Address") {
	$UpdPhoneSQL = "UPDATE phone SET fk_address_id=0 WHERE fk_contact_id=$id AND phone_id = $phonekey[$x]";
   }
   else {
	$UpdPhoneSQL = "UPDATE phone SET phone_type = '$AddrType[$x]', number='$PhoneNo[$x]' WHERE fk_contact_id=$id AND fk_address_id = $addrkey[$x] AND phone_id = $phonekey[$x]";
   }
	$UpdPhone   = mysql_query($UpdPhoneSQL);
	$x = $x + 1;
}

// Update Phone db
$y = $x;
while ($y <= $phones) { 
	$UpdPhoneSQL = "UPDATE phone SET phone_type = '$AddrType[$y]', number='$PhoneNo[$y]' WHERE fk_contact_id=$id AND phone_id = $phonekey[$y]";

	$UpdPhone   = mysql_query($UpdPhoneSQL);
	$y = $y + 1;
}
$Message = "Contact Successfully Updated";
include("contactlist.php")
?>
Return current item: Mozart