php - 无法更新我的 mysql 数据库

标签 php mysql

<分区>

所以我的 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>

最佳答案

我认为这是“我”的问题。你可以改变

 mysql_query($conn, $sqlemailtwo); to mysqli_query($conn, $sqlemailtwo);

关于php - 无法更新我的 mysql 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40704902/

相关文章:

php - 使用 PHP exec 调用 MySQL exe 不起作用

php - 如何安装phpUnit测试?

javascript - 改变div里面的颜色,如果有的话?

MYSQL数据库设计,大表间查询

mysql - 如何创建新数据库,其中包含 mysql 中旧数据库中的一些表

php - php 创建多个复选框

javascript - 我可以直接以具有 GET 方法的表单发送编码信息吗?

php - 来自另一个用户的 DBus

javascript - 将 echo 值从 php 页面传递到 javascript 显示垃圾数据

MySQL 左连接和右字段空检查