Location: PHPKode > projects > GEStione SOci > member_save.php
<?

/*
	CONFIGURAZIONE
*/
switch ($p_action) {
	case "member_insert":
		$action_retry = "member_new";
		$action_post = "member_detail";
		break;
	case "member_update":
		$action_retry = "member_detail";
		$action_post = "member_detail";
		break;
	case "member_delete":
		$action_retry = "member_detail";
		$action_post = "member_query_result";
		break;
}

/*
	CONTROLLO SINTATTICO E SEMANTICO
*/
if ($p_name == "") {
	retry($action_retry, "Campo NOME obbligatorio.");
	exit;
}
if ($p_surname == "") {
	retry($action_retry, "Campo COGNOME obbligatorio.");
	exit;
}

$p_email = (($p_email == '') ? ("null") : ("'$p_email'"));

$p_tax_code = (($p_tax_code == '') ? ("null") : ("'$p_tax_code'"));

if (($p_birthdate != "") && !($birthdate = to_mysql_date($p_birthdate))) {
	retry($action_retry, "Campo DATA DI NASCITA invalido.");
	exit;
}
$birthdate = (($birthdate == '') ? ("null") : ("'$birthdate'"));

if (($p_print_application_date != "") && !($print_application_date = to_mysql_date($p_print_application_date))) {
	retry($action_retry, "Campo DATA STAMPA DOMANDA invalido.");
	exit;
}
$print_application_date = (($print_application_date == '') ? ("null") : ("'$print_application_date'"));

if (($p_acceptance_date != "") && !($acceptance_date = to_mysql_date($p_acceptance_date))) {
	retry($action_retry, "Campo DATA ACCETTAZIONE invalido.");
	exit;
}
$acceptance_date = (($acceptance_date == '') ? ("null") : ("'$acceptance_date'"));

$p_membership_card_number = (($p_membership_card_number == '') ? ("null") : ("'$p_membership_card_number'"));

/*
	PREPARAZIONE STATEMENT SQL
*/
switch ($p_action) {
	case "member_insert":
		$sttmnt = "insert into tmember (
			name,
			surname,
			member_type_id,
			email,
			phone_mobile,
			phone_home,
			tax_code,
			birthplace,
			birthdate,
			address,
			zip_code,
			city,
			province_code,
			flag_honorary,
			flag_activist,
			amount,
			flag_unwanted,
			print_application_date,
			acceptance_date,
			membership_card_number,
			registration_date
		) values (
			'$p_name',
			'$p_surname',
			'$p_member_type_id',
			$p_email,
			'$p_phone_mobile',
			'$p_phone_home',
			$p_tax_code,
			'$p_birthplace',
			$birthdate,
			'$p_address',
			'$p_zip_code',
			'$p_city',
			'$p_province_code',
			'$p_flag_honorary',
			'$p_flag_activist',
			'$p_amount',
			'$p_flag_unwanted',
			$print_application_date,
			$acceptance_date,
			$p_membership_card_number,
			sysdate()
		)";
		break;
	case "member_update":
		$sttmnt = "update tmember set
			name = '$p_name',
			surname = '$p_surname',
			member_type_id = '$p_member_type_id',
			email = $p_email,
			phone_mobile = '$p_phone_mobile',
			phone_home = '$p_phone_home',
			tax_code = $p_tax_code,
			birthplace = '$p_birthplace',
			birthdate = $birthdate,
			address = '$p_address',
			zip_code = '$p_zip_code',
			city = '$p_city',
			province_code = '$p_province_code',
			flag_honorary = '$p_flag_honorary',
			flag_activist = '$p_flag_activist',
			amount = '$p_amount',
			flag_unwanted = '$p_flag_unwanted',
			print_application_date = $print_application_date,
			acceptance_date = $acceptance_date,
			membership_card_number = $p_membership_card_number
		where
			member_id = $p_member_id";
		break;
	case "member_delete":
		$sttmnt = "delete from tmember where member_id = $p_member_id";
		break;
}

/*
	ESECUZIONE STATEMENT SQL
*/
if (!($result = mysql_query($sttmnt))) {
	retry($action_retry, mysql_error());
	exit;
}

switch ($p_action) {
	case "member_insert":
		$member_id = mysql_insert_id();
		break;
	case "member_update":
		$member_id = $p_member_id;
		break;
}

$message = "Operazione Completata";

/*
	REDIRECT E USCITA
*/
header("Location: index.php?p_action=$action_post&p_member_id=$member_id&p_action_message=$message");

?>
Return current item: GEStione SOci