<!DOCTYPE html>
<html>
<head>
	<?php include('include/head.php'); ?>
	
	<!-- <title>Add Gallery </title> -->
</head>
<body>
	<?php include('include/header.php'); ?>
	<?php include('include/sidebar.php'); ?>
	<div class="main-container">
		<div class="pd-ltr-20 customscroll customscroll-10-p height-100-p xs-pd-20-10">
			<div class="min-height-200px">
				<div class="page-header">
					<div class="row">
						<div class="col-md-6 col-sm-12">
							<div class="title">
								<h4>Update City</h4>
							</div>
							<nav aria-label="breadcrumb" role="navigation">
								<ol class="breadcrumb">
									<li class="breadcrumb-item"><a href="dashboard.php">Dashboard</a></li>
									<li class="breadcrumb-item"><a href="#">City</a></li>
									<li class="breadcrumb-item"><a href="view_city.php">View City</a></li>
									
                  					<li class="breadcrumb-item active" aria-current="page">Update City</li>
								</ol>
							</nav>
						</div>
						<div class="col-md-6 col-sm-12 text-right">
              <div class="dropdown">
                <a class="btn btn-primary" href="view_city.php" role="button">
                  View City
                </a>
              </div>
            </div>
					</div>
				</div>


				
<div class="pd-20 bg-white border-radius-4 box-shadow mb-30">
					<div class="clearfix">
						<div class="pull-left">
							<!-- <h4 class="text-blue">Add Video</h4> -->
						</div>
						
					</div><br> 
					
					<form method="post" enctype="multipart/form-data">
			 <?php 
                $sel=mysqli_query($connect,"select * from tbl_city where fld_city_id='".$_GET['fld_city_id']."'") or die(mysqli_error($connect));
                $fetch=mysqli_fetch_array($sel);
              ?> 		
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">State Name <span class="text-danger">*</span> : </label>
							<div class="col-sm-12 col-md-10">
								<select name="state" class="form-control" id="state" required="">
				                    <option value="">Select State</option>
				                    <?php
				                        
				                        $query1=mysqli_query($connect,"select * from tbl_state where fld_state_delete='0' order by fld_state_id desc");
				                        while($row=mysqli_fetch_assoc($query1)){
				                          extract($row);

				                      ?>
				                    <option value="<?php echo $row['fld_state_id'];?>" <?php if ($fetch['fld_state_id']==$row['fld_state_id']){echo "selected";} ?>><?php echo $row['fld_state_name'];?></option>
				                    <?php  }?>
				                </select>
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">City Name</label>
							<div class="col-sm-12 col-md-10">
								<input type="text" name="city" class="form-control" value="<?php echo $fetch['fld_city_name']?>" required="" oninput="this.value = this.value.replace(/[^a-zA-Z\s.]/g, '').replace(/(\..*)\./g, '$1');">
							</div>
						</div>
												
						<div class="form-group row">
							<div class="col-sm-12 col-md-10">
							<center><input class="btn btn-success" value="Update" type="submit" name="update">&nbsp;
								<a href="view_city.php" class="btn btn-warning">Back</a></center>
							</div>
						</div>
					</form>
<?php

//error_reporting(0);
    
    if(isset($_POST['update']))
    {
     extract($_POST);
     // $abc=mysqli_query($connect,"select * from tbl_city where fld_city_id!='".$_GET['fld_city_id']."' and fld_state_id='".$_GET['fld_state_id']."' and fld_city_name='".$_POST['city']."'");

$abc=mysqli_query($connect,"select * from tbl_city where fld_city_name='".$_POST['city']."' and fld_city_id!='".$_POST['city']."' and fld_state_id='".$_POST['state']."' and fld_city_delete='0'");

	if(mysqli_num_rows($abc)==1)
	{
	    echo "<script>";
	    echo "alert('City Alrady Exist');";
	    //echo "window.location.href='view_course_details.php';";
	    echo "</script>";
	}
	else
	{

     $update=mysqli_query($connect,"update tbl_city set
                fld_state_id='".$_POST['state']."',
                fld_city_name='".$_POST['city']."'
                where fld_city_id='".$_GET['fld_city_id']."'") or die(mysqli_error($connect));
     if($update)
        {
           echo '<script type="text/javascript">';
           echo " alert('City Updated Successfully');";
           echo 'window.location.href = "view_city.php";';
           echo '</script>';
      	}
     	else
     	{
           echo '<script type="text/javascript">';
           echo "alert('City not Updated');";
             echo '<script>';
                            
        }
    }

}
?>                 
	
					 
	</div>
			<?php include('include/footer.php'); ?>
		</div>
	</div>
	<?php include('include/script.php'); ?>
	
</body>
</html>
