Hallo Forum,
ich arbeite an meinen Benutzer Einstellungen, welche man dann ändern kann.
Nun habe ich auch ein Script dafür, welches noch einen Fehler [error=sqlerror2] enthält.
Zudem wollte ich mal frage wie ihr so etwas handhaben würdet, weil momentan muss ich ja noch alle werte überschreiben.
Script:
ich arbeite an meinen Benutzer Einstellungen, welche man dann ändern kann.
Nun habe ich auch ein Script dafür, welches noch einen Fehler [error=sqlerror2] enthält.
Zudem wollte ich mal frage wie ihr so etwas handhaben würdet, weil momentan muss ich ja noch alle werte überschreiben.
Script:
PHP-Code:
<?php
session_start();
if(isset($_POST['settings-submit'])){
require 'dbh.inc.php';
$username = $_POST['uid'];
$email = $_POST['mail'];
$password = $_POST['pwd'];
$confirmpassword = $_POST['cpwd'];
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='" . $_SESSION['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) VALUES (?, ?, ?) WHERE id='" . $_SESSION['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, "sss", $username, $email, $hashedPwd);
mysqli_stmt_execute($stmt);
header("Location: logout.inc.php?settings=success");
exit();
}
}
}
}
mysqli_stmt_close($stmt);
mysqli_close($conn);
}
else {
header("Location: ../settings.php");
exit();
}
Kommentar