<?php
if (isset ( $_POST ['send_fieldname'] ) && isset ( $_POST ['send_tablename'] ) && isset ( $_POST ['send_newvalue'] )) {
	$field = $_POST ['send_fieldname'];
	$tablename = $_POST ['send_tablename'];
	$newval = $_POST ['send_newvalue'];
	
	$getfieldname = explode ( "___", $field );
	
	$firsttable = 'DESCRIBE `main_salaryslip`';
	$totaldata_firsttable = $db->run ( $firsttable )->fetchAll ();
	
	$arr = array ();
	foreach ( $totaldata_firsttable as $row ) {
		$arr [] = $row ['Field'];
	}
	
	if (! in_array ( $newval, $arr )) {
		foreach ( $totaldata_firsttable as $row ) {
			if ($row ['Field'] == $getfieldname [1]) {
				$convert_newval = preg_replace ( '/[^a-zA-Z0-9\']/', '_', $newval );
				$query = $db->run ( "alter table `$tablename` change `$getfieldname[1]` `$convert_newval` varchar(255)" );
			
			}
		}
		echo 1;
	} else {
		echo 2;
	}
}
?>