I have a project, where users can edit their own profile. I currently have a login/register page. Now its time for a user-edit page. The site works with sessions so, whenever they come back they see myprofile in the navbar.
I've tested everything in PHP, to update the account.
I currently have 2 files where the update-profile scripts works with.
1 is the profile.php, the other in includes/update.inc.php
In includes/login.inc.php
I have already assigned a session.
if ($pwdCheck == false) {
header("Location: ../index.php?error=wrongpassword");
exit();
}
else if ($pwdCheck == true) {
session_start();
$_SESSION['userId'] = $row['idUsers'];
$_SESSION['userUid'] = $row['uidUsers'];
header("Location: ../index.php?logging=succes");
exit();
So yeah that was from the includes/login.inc.php.
Now when u go to your profile it checks if $_SESSION['userId'] == true.
Now the following:
This is my profile.php
<?php
require "header.php";
require "includes/dbh.inc.php";
$sessionkk = $_SESSION['userId'];
error_reporting(E_ALL); ini_set('display_errors', 1);
$query = "SELECT idUsers, uidUsers, emailUsers,pwdUsers,Voornaam,Tussenvoegsel,Achternaam,Schooljaar,School,Opleiding,Niveau,Recht,Taal
,
printerA,printerB,printerC FROM users WHERE idUsers = '$sessionkk'";
$result = $conn->query($query) or die($conn->error);
if(mysqli_num_rows($result) > 0){
while ($row = mysqli_fetch_assoc($result)){
$id = $row['idUsers'];
$username = $row['uidUsers'];
$email = $row['emailUsers'];
$password = $row['pwdUsers'];
$voornaam = $row['Voornaam'];
$tussenvoegsel = $row['Tussenvoegsel'];
$achternaam = $row['Achternaam'];
$Schooljaar = $row['Schooljaar'];
$School = $row['School'];
$Opleiding = $row['Opleiding'];
$niveau = $row['Niveau'];
$Taal = $row['Taal'];
$printera = $row['printerA'];
$printerb = $row['printerB'];
$printerc = $row['printerC'];
}
}
?>
<div class="adminform">
<h2>gegevens aanpassen</h2><br/>
<form action="includes/update.inc.php" method="POST">
<input type="text" name="username" placeholder="Username"
value="
<?php if(isset($_GET['username'])){echo $_GET['username'];}?>"><br/><br/>
<input type="text" name="email" placeholder="E-mail" value="<?php
if(isset($_GET['email'])){echo $_GET['email'];}?>"><br/><br/>
<input type="text" name="" placeholder="Schooljaar" value="<?php
if(isset($_GET['Schooljaar'])){echo $_GET['Schooljaar'];}?>"><br/><br/>
<input type="text" name="email" placeholder="E-mail" value="<?php
if(isset($_GET['School'])){echo $_GET['School'];}?>"><br/><br/>
<button type="submit" name="adminupdate">Aanpassen</button>
</form>
<?php
echo "" . $id;
?>
</div>
<?php
?>
Here i conclude everything. The formname etc etc.
You can also see how i make a $sessionkk = $_SESSION['userId'];
The $sessionkk works with the
Here is the include/update.inc.php
<?php
session_start();
require "dbh.inc.php";
if(isset($_POST['adminupdate'])){
$sql = "UPDATE users SET uidUsers= '?', emailUsers = '?', Schooljaar =
'?',
School = '?' WHERE idUsers = '.$sessionkk.'";
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt, $sql)){
header("Location: ../profile.php?error=sqlerror");
exit();
} else{
mysqli_stmt_bind_param($stmt, "ssss", $username, $email,
$Schooljaar, $School);
mysqli_stmt_execute($stmt);
header("Location: ../profile.php?update=succes");
exit();
}
}
?>
I tried the $sql query with just the ID from the database so it would be like this:
$sql = "UPDATE users SET uidUsers= '?', emailUsers = '?', Schooljaar = '?',
School = '?' WHERE idUsers = '4'";
and this would work. But i want to grab the id from the user who is logged in. Sorry that the code is so messy, i dont know how to upload code correctly here.
Thank you