所以我的mysql查询有问题。当我尝试更改“电子邮件”列时,它会遍历所有if语句,它只显示我已成功更改了我的电子邮件但由于某些原因它没有。请告诉我错误在哪里......可能是傻事,但由于某些原因我找不到它。
这是编码:
<?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>
答案 0 :(得分:0)
我认为这是'我'的问题。你可以改变
mysql_query($conn, $sqlemailtwo); to mysqli_query($conn, $sqlemailtwo);