<?php
include("../conn.php"); 
if (isset($_POST['ready'])){

	if ($_POST['password2'] != $_POST['password3']){
		$msg="<font color=\"red\">NewPassword is not thesame with re-entered password.</font>";
	}else{

			
			
			$password = mysqli_escape_string($conn, $_POST['password']);
			
			
			$password2 = mysqli_escape_string($conn, $_POST['password2']);
			
			//---------------------------------------------
				$query  = "SELECT * FROM artist WHERE password = '$password'";				
				$result = mysqli_query($conn, $query) or die(mysqli_error($conn));

				if (mysqli_num_rows($result) == 0) {
				 	$msg="<font color=\"red\">Sorry Old Password not registered please enter correct existing password.</font>";
				}else{		
			//----------------------------------------------		
					$sql = "UPDATE artist SET password='$password2' WHERE password= '$password'";
							mysqli_query($conn, $sql) or die(mysqli_error($conn));
					
					$msg="<font color=\"blue\">Password Successfully changed.</font>";
				}
			
			
	
	}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Admin</title>

    <!-- Bootstrap CSS -->    
    <link href="assets/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- bootstrap theme -->
    <link href="assets/dist/css/bootstrap-theme.css" rel="stylesheet">
    <!--external css-->
    <!-- font icon -->
    <link href="assets/dist/css/elegant-icons-style.css" rel="stylesheet" />
    <link href="assets/dist/css/font-awesome.css" rel="stylesheet" />
    <!-- Custom styles -->
    <link href="assets/dist/css/style.css" rel="stylesheet">
    <link href="assets/dist/css/style-responsive.css" rel="stylesheet" />

  
</head>

  <body class="login-img3-body">

    <div class="container">

      <form class="login-form" method="post" action="change_pw.php">        
        <div class="login-wrap">
       
       
       	 <br/>                  
          
             <a href="index.php">Back</a>
           
            
            <h2>
             Change password
            </h2>   
           	
			
						<?php
						if(isset($msg)){
							print "<p align='center'>$msg</p>";
						}
						?>
						
                        
            <div class="input-group">               
                <input name="password" type="textbox" class="form-control" placeholder="Old Password" required>
            </div>
            
            <div class="input-group">               
                <input name="password2" type="textbox" class="form-control" placeholder="New Password" required>
            </div>
            
            <div class="input-group">               
                <input name="password3" type="textbox" class="form-control" placeholder="Re-enter New password" required>
            </div>

            <button class="btn btn-success btn-lg btn-block" type="submit">Change</button>
            <input name="ready" type="hidden" id="ready" value="go" />
        </div>
      </form>

    </div>


  </body>
</html>
