<?php session_start();?>
<?php require_once('open_connection.php');?>
<!--link href='blue/style.css' rel='stylesheet' type='text/css' /-->
<link href='css/imagetable.css' rel='stylesheet' type='text/css' />
<!DOCTYPE html>
<html>
<head>
      <title>PICCSB e-Directory System</title>

</head>
<body bgcolor="#333333"> 
<table width="100%" border="0" align="center">
<tr>
<td width="15%" bgcolor="#333333">&nbsp;</td>
<td width="70%" align="center" bgcolor="#FFFFFF" > 

<table width="100%" border="0" align="center">

<!-- row for header picc 1 -->
<tr>  
     <th width="100%" colspan="4"><img src="images/header-cox.jpg" width="100%" height="30%"></th>
</tr>


<!-- row for header picc 2 -->
<tr>
     <th width="100%" colspan="4"><img src="images/eoffice-cox.jpg" width="100%" height="15%"></th>
</tr>

<!-- calling frame -->	
<tr>
    <td colspan="1" width="10%" align="center"><?php include("header.php");?></td>
	
</tr>
<tr>

<td colspan="3" width="90%" align="center" >
<tr><td>&nbsp;</td></tr>
<tr><td align="left">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						<?php
								echo 'Welcome: ' . $_SESSION['username'];
								?>
							<a href="cust_FnB_Login.php"><img src="images/logout3.gif" align="right"></a>						
							</td>
</tr>
<tr><td>
<h2 align="center">UPDATE CUSTOMER RECORD</h2>
<?php
       $cust_id = $_GET['cust_id'];

//echo $cust_id;

       $sql1 = "SELECT * FROM tbl_dir_fnb_customer WHERE cust_id = '$cust_id'";
																		
				$result1 = mysql_query($sql1) or die('Query failed. ' . mysql_error());
				// $row = mysql_fetch_array($result, MYSQL_ASSOC);			
				$row1=mysql_fetch_array($result1);
			    $cust_id=$row1['cust_id'];
				$cust_name=$row1['cust_name'];
			
		?>
				
				<form  method="post" >
<table class="imagetable" align="center">
<tr><td>Salutation</td><td> : </td><td><select name="cust_salutation" class="input-xlarge">
						<option ><?php echo  $row1['cust_salutation']; ?></option>
						<option >Mr</option>
						<option >Ms</option>
                                  
                                                    </select></td></tr>
<tr><td>Customer Name</td><td> : </td><td><input type="text" size="100" maxlength="100"  value="<?php echo htmlentities($row1['cust_name']);?>" name="cust_name"required></td></tr>
<tr><td>Company</td><td> : </td><td><input type="text" size="100" maxlength="100" name="cust_company" value="<?php echo $row1['cust_company']?>"></td></tr> 
<tr><td>Position</td><td> : </td><td><input type="text" size="50" maxlength="50" name="cust_position" value="<?php echo $row1['cust_position']?>"></td></tr>
<tr><td>Contact</td><td> : </td><td><input type="text" size="50" maxlength="50" name="cust_contact" value="<?php echo $row1['cust_contact']?>"></td></tr>
<tr><td>Email</td><td> : </td><td><input type="text" size="80" maxlength="80" name="cust_email" value="<?php echo $row1['cust_email']?>"></td></tr>
<tr><td>Address</td><td> : </td><td><input type="text" size="100" maxlength="100" name="cust_address1" value="<?php echo $row1['cust_address1']?>"></textarea></td></tr>
<tr><td>&nbsp;</td><td> : </td><td><input type="text" size="100" maxlength="100" name="cust_address2" value="<?php echo $row1['cust_address2']?>"></td></tr>
<tr><td>&nbsp;</td><td> : </td><td><input type="text" size="100" maxlength="100" name="cust_address3" value="<?php echo $row1['cust_address3']?>"></td></tr>
<tr><td>&nbsp;</td><td> : </td><td><input type="text" size="100" maxlength="100" name="cust_address4" value="<?php echo $row1['cust_address4']?>"></td></tr>
<tr><td>Postcode</td><td> : </td><td><input type="text" size="100" maxlength="100" name="cust_postcode" value="<?php echo $row1['cust_postcode']?>"></td></tr>
<tr><td>City</td><td> : </td><td><input type="text" size="100" maxlength="100" name="cust_city" value="<?php echo $row1['cust_city']?>"></td></tr>
<tr><td>State</td><td> : </td><td><select name="state_name" >
                                <option ><?php echo  $row1['state_name']; ?></option>
                                <?php $state_query=mysql_query("select * from tbl_ref_state")or die(mysql_error());
                                       while($row_state=mysql_fetch_array($state_query)){?>
                                <option> <?php echo $row_state['state_name']; ?>
                                <?php } ?>
                                </option>
                              </select></td></tr>
							  <input type="hidden" name="cust_id" value="<?php echo $row1['cust_id']?>">
<tr><td colspan="3" align="center">

<input type="submit" value="save" name="save" id="save" class="myButton">
<input type="button" class="myButton" value="CUSTOMER'S LIST" onClick="window.location.href='cust_FnB_view.php'"></td></tr>

</table>
</td></tr>
</form>

<?php
// escape variables for security
if (isset($_POST['save'])){
       
					$cust_id = $row1['cust_id']; 
		    $cust_salutation = $_POST['cust_salutation'];
		 		  $cust_name =$_POST['cust_name'];
		       $cust_company = $_POST['cust_company'];
			  $cust_position = $_POST['cust_position'];
			   $cust_contact = $_POST['cust_contact'];
			     $cust_email =$_POST['cust_email'];
			  $cust_address1 = $_POST['cust_address1'];
			  $cust_address2 = $_POST['cust_address2'];
			  $cust_address3 = $_POST['cust_address3'];
			  $cust_address4 = $_POST['cust_address4'];
			  $cust_postcode = $_POST['cust_postcode'];
				  $cust_city = $_POST['cust_city'];
				 $state_name = $_POST['state_name'];
   
// insert record into database
$sql="update tbl_dir_fnb_customer set cust_salutation='$cust_salutation',  cust_name='$cust_name',cust_company='$cust_company',cust_position='$cust_position',cust_contact='$cust_contact', cust_email='$cust_email',  cust_address1='$cust_address1',cust_address2='$cust_address2',cust_address3='$cust_address3',cust_address4='$cust_address4',cust_postcode='$cust_postcode',cust_city='$cust_city', state_name='$state_name' where cust_id='$cust_id'";
	
$result=mysql_query($sql);
if($result)
echo "<script language='javascript'>window.location='cust_FnB_view.php'</script>";

else
   
   echo 'Unsuccessfull update';
   }
?>
<!-- row for footer -->	
<tr>
	<th align="center" colspan="4">
	<?php include ('footer.php'); ?>
		
	</th>
</tr>

<!--- end for ruang kerja 80% -->
</table>

</td>

<td width="15%" bgcolor="#333333">&nbsp;</td>

</tr>

<!--- end for ruang kerja 100% -->
</table>

</body>
</html>	