-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchangepasswordscript.php
More file actions
22 lines (22 loc) · 942 Bytes
/
Copy pathchangepasswordscript.php
File metadata and controls
22 lines (22 loc) · 942 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
session_start();
$oldpassword = $_POST["oldpassword"];
$newpassword = $_POST["newpassword"];
$connection = new mysqli($_SESSION["sql_hostname"], $_SESSION["sql_username"], $_SESSION["sql_password"], $_SESSION["database_name"]);
if($connection->connect_error){
die("Connection failed" . $connection->connect_error);
}
$query = "SELECT username, user_password FROM user_table WHERE username='".$_SESSION["username"]."'";
$result = $connection->query($query);
$row = $result->fetch_assoc();
if($row["user_password"] == $oldpassword){
$sql = "UPDATE user_table SET user_password='$newpassword' WHERE username='".$_SESSION["username"]."'";
if($connection->query($sql) === true){
header("Location: index.php");
}else{
echo "Failed ".$connection->error;
}
}else{
echo "Old password doesn't match account!";
}
?>