Ja der Code sieht jetzt wie folgt aus:
Sollte so eigentlich richtig sein.
PHP:
<?php
session_start();
if(isset($_POST['settings-submit'])){
require 'dbh.inc.php';
$username = htmlspecialchars($_POST['uid'], ENT_QUOTES, "UTF-8");
$email = htmlspecialchars($_POST['mail'], ENT_QUOTES, "UTF-8");
$password = htmlspecialchars($_POST['pwd'], ENT_QUOTES, "UTF-8");
$confirmpassword = htmlspecialchars($_POST['cpwd'], ENT_QUOTES, "UTF-8");
$id = htmlspecialchars($_SESSION['userId'], ENT_QUOTES, "UTF-8");
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
header("Location: ../settings.php?error=invalidmail");
exit();
}
else if(!preg_match("/^[\w\- ]*$/", $username)) {
header("Location: ../settings.php?error=invalidusername");
exit();
}
else if($password !== $confirmpassword){
header("Location: ../settings.php?error=passwordcheck");
exit();
}
else {
$sql = "SELECT * FROM users WHERE id='" . $id . "'";
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt, $sql)){
header("Location: ../settings.php?error=sqlerror1");
exit();
}
else {
mysqli_stmt_bind_param($stmt, "s", $username);
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
$resultCheck = mysqli_stmt_num_rows($stmt);
if($resultCheck == 0){
header("Location: ../settings.php?error=usertaken");
exit();
}
else {
$sql = "UPDATE users SET uid=?, email=?, pwd=? WHERE id= ?;";
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt, $sql)){
header("Location: ../settings.php?error=sqlerror2");
exit();
}
else {
$hashedPwd = password_hash($password, PASSWORD_DEFAULT);
mysqli_stmt_bind_param($stmt, "sssi", $username, $email, $hashedPwd, $_SESSION['id']);
mysqli_stmt_execute($stmt);
printf("Error: %s.\n", mysqli_stmt_error($stmt));
header("Location: logout.inc.php?settings=success");
exit();
}
}
}
}
mysqli_stmt_close($stmt);
mysqli_close($conn);
}
else {
header("Location: ../settings.php");
exit();
}
Sollte so eigentlich richtig sein.