$location=trim(ucfirst($_POST['name'])); $parent_loc=$_POST['parent'];
if (isset ( $_POST ['bt_submit'] ))
{
if($location=='')
{
$err_loc="Required";
}
elseif(!preg_match("/^[a-z A-Z]+$/",$location))
{
$err_loc="Only alphabits allowed.";
}
else{
$select_loc = $db->select ("SELECT name From locations WHERE name='{$location}'") or die('error in selection.');
$count=mysql_num_rows($select_loc);
if($count==0)
{
$id = $db->insert_sql ( "INSERT INTO `locations` (`name` ,`parent`) VALUES ('" . ucfirst($_POST ['name']) . "', '" . $_POST ['parent'] . "')" );
$msg="Location inserted";
}
else{
$msg="$location Already Exist";
}
//$db->print_last_query();
print "";
exit ();
}
}
if (isset ( $_POST ['bt_update'] ))
{
$id = $db->update_sql ( "update `locations` set `name`='" . ucfirst($_POST ['name']) . "' ,`parent`='" . $_POST ['parent'] . "' where locationid=" . $_GET ['location'] );
//$db->print_last_query();
print "";
}
if (isset ( $_GET ['del'] ))
{
$id = $db->delete ( "delete from locations where locationid=" . $_GET ['del'] );
//$db->print_last_query();
print "";
}
?>
=$msg;?>