<?php
 $dbhost = '192.168.0.47';
         $dbuser = 'root';
         $dbpass = 'root';
         $conn = mysql_connect($dbhost, $dbuser, $dbpass);
         if(! $conn ) {
            die('Could not connect: ' . mysql_error());
			
         }
		 mysql_select_db("moeabed", $conn);
		 
		 $actionmode = $_GET['actionmode'];
         $name = $_GET['name'];
	     $address = $_GET['address'];
		 $phone = $_GET['phone'];
		 $CustomerId = $_GET['CustomerId'];
		 include("functions_abed.php");
if($actionmode == "insert")
    {
	$querycustomers_insert = "INSERT INTO customers(CustomerName, CustomerAddress, CustomerPhoneNumber)
	VALUES('$name','$address','$phone')";
	$result_insert = mysql_query($querycustomers_insert,$conn);
	if($result_insert){
		$message = "Inserted Successfully!";
	}
	else{
		$message = "Error in inserting!";
	}
	echo $message;
	echo "[BRK]";
	drawTable($conn);
	echo "[BRK]";
}
else
	if($actionmode == "setedit")
	{
		$querycustomers_setedit = "SELECT CustomerId,CustomerAddress,CustomerName,CustomerPhoneNumber 
		                          FROM customers
		                          WHERE CustomerId = '$CustomerId'";
	   $result_setedit = mysql_query($querycustomers_setedit,$conn);
	   $row_setedit    = mysql_fetch_array($result_setedit);
	   extract($row_setedit);
	echo $CustomerId;
	echo "[BRK]";
	echo $CustomerAddress;
	echo "[BRK]";
	echo $CustomerName;
	echo "[BRK]";
	echo $CustomerPhoneNumber;
	echo "[BRK]";
	
		
	}
	else
		if($actionmode == "edit"){
			$querycustomers_update = "UPDATE customers
			                          SET CustomerName = '$name',
									      CustomerAddress = '$address',
										  CustomerPhoneNumber = '$phone'
									  WHERE CustomerId = '$CustomerId'";
								
		$result_update = mysql_query($querycustomers_update,$conn);
		if($result_update){
			$message = "Updated Successfully!";
		}
		else{
			$message = "Error in Updating!";
		}
		echo $message;
		echo "[BRK]";
		drawTable($conn);
	echo "[BRK]";
	}
                
?>