So I have a problem with my mysql query. When I try to change the "email" column, it goes through all the if statements and it only shows that I've changed my email successfully but for some reasons it doesn't. Please tell me where the mistake is... probably it's something silly, but I cannot find it for some reason.
here is the coding:
<?php
session_start();
include 'connection/db_connect.php';
$sessionname = $_SESSION['name'];
$sql = "SELECT * FROM registered WHERE userName='$sessionname'";
$result = mysqli_query($conn, $sql);
$currentprofile = "Your profile";
$selectedprofile = "<h1>Your profile</h1>";
while($row = mysqli_fetch_array($result, MYSQL_ASSOC)){
$username = $row['userName'];
$password = $row['password'];
$email = $row['email'];
$sessionid = $row['id'];
}
$erroremail = null;
$changeEmail = $_POST['changeEmail'];
$changeEmailValue = $_POST['changeEmailValue'];
$changePassword = $_POST['changePassword'];
$changePasswordNew = $_POST['changePasswordNew'];
$changePasswordRepeat = $_POST['changePasswordRepeat'];
if(isset($changeEmail)){
if(!empty($changeEmailValue)){
$sqlemail = "SELECT email FROM registered where email='$changeEmailValue'";
$resultemail = mysqli_query($conn, $sqlemail);
if(mysqli_num_rows($resultemail) >= 1){
$erroremail = "<p style='color:red;'>This email is already in use by another user!</p>";
} else {
$sqlemailtwo = "UPDATE registered SET email='$changeEmailValue' WHERE id='$sessionid'";
mysql_query($conn, $sqlemailtwo);
$erroremail = "<p style='color:green;'>You updated ypur email successfully!</p>";
}
} else {
$erroremail = "<p style='color:red;'>You didn't enter email!</p>";
}
}
if($sessionname == null){
header ('Location: index.php'); // proverka za login
}
?>
<html>
<head>
<title><?php echo $currentprofile; ?></title>
<style>
</style>
</head>
<body>
<div>
<?php echo "Hello, ".$username; ?> | <a href='logout.php'>Logout</a>
<div style='width: 230px; height: 100%;'>
<span><?php echo $selectedprofile; ?></span>
<br>
Email:
<?php echo $erroremail; ?>
<form method='post' action='?=changeEmail'>
<input type='email' name='changeEmailValue' value='<?php echo $email; ?>'>
<input type='submit' name='changeEmail' value='Change'>
</form>
<hr>
Password:
<form method='post' action='?=changePassword'>
<input type='password' name='changePasswordCurrent' value='' placeholder='Your current password'>
<input type='password' name='changePasswordNew' value='' placeholder='New password'>
<input type='password' name='changePasswordRepeat' value='' placeholder='Repeat new password'>
<input type='submit' name='changePassword' value='Change'>
</form><br>
<hr>
Your IP adress:
<?php ?>
</div>
</body>
</html>