<?php
session_start();
require_once 'includes/database.php';
include 'includes/funcs.php';
$db=new MySQLDatabase();
$db->open_connection();
$user = $_SESSION['reusername'];
$email = $_REQUEST['email'];
if($_REQUEST['e'] === '0'){													// add new
$cname = strtoupper($_REQUEST['cname']);	$phone = $_REQUEST['phone']; 	$city = strtoupper($_REQUEST['city']);	$cadd = strtoupper($_REQUEST['cadd']);															
$query = "INSERT INTO customers (cname, address, phone, city, email, us, ts) VALUES ('".$cname."', '".$cadd."', '".$phone."' , '".$city."', '".$email."', '".$user."', '".date("Y-m-d H:i:s")."')";
$result = mysqli_query($db->connection, $query) or die(mysqli_error($db->connection) ); 
$db->close_connection();
echo "OK";  
}

else {																		// mod entry
$cname = strtoupper($_REQUEST['cname']);	$phone = $_REQUEST['phone']; 	$city = strtoupper($_REQUEST['city']);	$cadd = strtoupper($_REQUEST['cadd']);
$ocname = $_REQUEST['ocname']; 
$query = "UPDATE customers SET cname = '$cname', phone = '$phone', email = '$email', city = '$city', address = '$cadd', us = '$user', ts ='".date("Y-m-d H:i:s")."' WHERE cname = '$ocname';"; 
$result = mysqli_query($db->connection, $query) or die(mysqli_error($db->connection) );
$db->close_connection();
echo "OK"; 
}

?>