I am working on creating user profile access and modifying information (like password, email or username- which obviously should be limited). The function itself works, but when trying to grab information from the username to check if it meets standards (which just 6 letters or longer isnt the best limiter). It hits the if statement, for if it is too short, but the array is not adding the new parameter/value when it hits it (I used a var_dump to double check on both pages). I tried array_push, but that just brought errors, and many posts say that the way I am doing it is right (if I set it up right). The array itself is created with just the value [“created” => “created”] if it does not exist (checked on every page load),
Profile.php:
[code=php]
<form action=”/ChangeUsername.php” method=”post”>
<input type=”text” name=”username”><br>
<input type=”submit” value=”Change Username”>
<?php if (isset($_SESSION[‘Errors’][‘UsernameChange’])){
echo “<p class=’errortext’>” . $_SESSION[‘Errors’][‘UsernameChange’] . “</p>”;
unset($_SESSION[‘Errors’][‘UsernameChange’]);
} ?>
</form>
ChangeUsername.php:
[code=php]
<?php
session_start();
$DBaccess = parse_ini_file(“../Users.ini”);
$NewUsername = $_POST[‘username’];
if (strlen($NewUsername) < 6){
$_SESSION[‘Errors’][‘UsernameChange’] = “Username is shorter than 6 characters”;
header(“location: /Profile.php”);
die();
} elseif(!isset($NewUsername)){
$_SESSION[‘Errors’][‘UsernameChange’] = “Username is empty”;
header(“location: /Profile.php”);
die();
} else {
echo “<br>”;
echo $NewUsername;
echo “<br>”;
echo $_SESSION[‘UserID’];
$dbhost = $DBaccess[‘dbhost’];
$username = $DBaccess[‘username’];
$password = $DBaccess[‘password’];
$dbname = $DBaccess[‘dbname’];
$pdo = new PDO(“mysql:host=$dbhost;dbname=$dbname;”, $username, $password);
$sql = “UPDATE Profiles SET Username=:newusername WHERE ID=:ID”;
$stmt = $pdo->prepare($sql);
$stmt->execute(array(
“:newusername”=>$NewUsername,
“:ID” => $_SESSION[‘UserID’]
));
$_SESSION[‘Username’] = $NewUsername;
header(“location: /Profile.php”);
die();
}
?>
I am not fully sure on arrays, as I have only used them by accessing pre-created or $_SESSION, but not an array in array. I want to use an array in session since it will refresh in every new session and it is easily accessible.