PHP Saving a vo to db with amfphp


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. public function saveContact( $contact )
  2. {
  3. if ( $contact[contact_id] == 0 )
  4. {
  5. //Insert net
  6. $sql = "INSERT INTO contacts
  7. VALUES ( NULL,
  8. '".$contact[contact_fname]."',
  9. '".$contact[contact_lname]."',
  10. '".$contact[contact_email]."',
  11. '".$contact[contact_url]."',
  12. '".$contact[contact_address]."',
  13. '".$contact[contact_city]."',
  14. '".$contact[contact_state]."',
  15. '".$contact[contact_zip]."',
  16. '".$contact[contact_photo]."',
  17. '".$contact[contact_locationid]."')
  18. ";
  19. if (!mysql_query( $sql ))
  20. {
  21. return false;
  22. }
  23. //Return the created contact
  24. return $this->getOne( mysql_insert_id() );
  25.  
  26. } else {
  27.  
  28. //Update Contact
  29. $id = $contact[contact_id];
  30.  
  31. $sql = "UPDATE contacts SET
  32. contact_fname = '".$contact[contact_fname]."',
  33. contact_lname = '".$contact[contact_lname]."',
  34. contact_email = '".$contact[contact_email]."',
  35. contact_url = '".$contact[contact_url]."',
  36. contact_address = '".$contact[contact_address]."',
  37. contact_city = '".$contact[contact_city]."',
  38. contact_state = '".$contact[contact_state]."',
  39. contact_zip = '".$contact[contact_zip]."',
  40. contact_photo = '".$contact[contact_photo]."',
  41. contact_locationid = '".$contact[contact_locationid]."'
  42. WHERE contact_id =".$id;
  43. if ( !mysql_query( $sql ) )
  44. {
  45. return false;
  46. }
  47. //Return contact
  48. return $this->getOne( $id );
  49. }
  50. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.