1
所以我有我的MySQL查询问题。当我尝试更改“电子邮件”列时,它会经历所有if语句,并且仅显示我已成功更改了电子邮件,但由于某些原因它没有成功。请告诉我错误在哪里......可能是愚蠢的,但由于某种原因我找不到它。无法更新我的MySQL分贝
这里是编码:
<?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)){
\t $username = $row['userName'];
\t $password = $row['password'];
\t $email = $row['email'];
\t $sessionid = $row['id'];
}
$erroremail = null;
$changeEmail = $_POST['changeEmail'];
$changeEmailValue = $_POST['changeEmailValue'];
$changePassword = $_POST['changePassword'];
$changePasswordNew = $_POST['changePasswordNew'];
$changePasswordRepeat = $_POST['changePasswordRepeat'];
if(isset($changeEmail)){
\t if(!empty($changeEmailValue)){
\t \t $sqlemail = "SELECT email FROM registered where email='$changeEmailValue'";
\t \t $resultemail = mysqli_query($conn, $sqlemail);
\t \t if(mysqli_num_rows($resultemail) >= 1){
\t \t \t $erroremail = "<p style='color:red;'>This email is already in use by another user!</p>";
\t \t } else {
\t \t \t $sqlemailtwo = "UPDATE registered SET email='$changeEmailValue' WHERE id='$sessionid'";
\t \t \t mysql_query($conn, $sqlemailtwo);
\t \t \t $erroremail = "<p style='color:green;'>You updated ypur email successfully!</p>";
\t \t }
\t } else {
\t \t $erroremail = "<p style='color:red;'>You didn't enter email!</p>";
\t }
}
if($sessionname == null){
\t header ('Location: index.php'); // proverka za login
}
?>
<html>
<head>
\t <title><?php echo $currentprofile; ?></title>
\t <style>
\t </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>
\t Email:
\t <?php echo $erroremail; ?>
\t <form method='post' action='?=changeEmail'>
\t \t <input type='email' name='changeEmailValue' value='<?php echo $email; ?>'>
\t \t <input type='submit' name='changeEmail' value='Change'>
\t </form>
<hr>
\t Password:
\t <form method='post' action='?=changePassword'>
\t \t <input type='password' name='changePasswordCurrent' value='' placeholder='Your current password'>
\t \t <input type='password' name='changePasswordNew' value='' placeholder='New password'>
\t \t <input type='password' name='changePasswordRepeat' value='' placeholder='Repeat new password'>
\t \t <input type='submit' name='changePassword' value='Change'>
\t </form><br>
<hr>
\t Your IP adress:
\t <?php ?>
</div>
</body>
</html>
不仅如此,而且'MYSQL_ASSOC'也。 –