gpt4 book ai didi

php - MYSQL UPDATE函数的正确使用

转载 作者:行者123 更新时间:2023-11-29 08:05:25 24 4
gpt4 key购买 nike

我正在使用 MySQL 查询来更新数据库中的信息。

我尝试从 localhost/phpmyadmin 更新信息,然后复制 localhost/phpmyadmin 中给出的代码。

问题是数据库中的信息/值没有更新。

下面是代码:

<?php

if(isset($_POST['updateProfile']))
{
$newUser = $_POST['newUsername'];
$newPass = $_POST['newPassword'];
$newConNum = $_POST['newContactNumber'];
$newAdd = $_POST['newAddress'];

include("dbconnect.php");

//avatarPATH
$filepath = "avatar/owner-".$_SESSION['username']."-fname-".$_SESSION['fname']."-l_name-".$_SESSION['lname']."-filename-".$_FILES["file"]["name"];

$checkQuery = "SELECT * FROM `users`.`info` WHERE username = '".$userName."' ";
$checkResult = $con->query($checkQuery);
$count = mysqli_num_rows($checkResult);

while ($rows = mysqli_fetch_array($checkResult, MYSQLI_ASSOC))

{
$username = $rows['username'];
$userpass = $rows['password'];
$firstName = $rows['firstname'];
$lastName = $rows['lastname'];
$ConNum = $rows['contact_number'];
$usrAdd = $rows['user_address'];
$avaImgPth = $rows['avatar_image_path'];
$adminLvl = $rows['admin_level'];
}

$query = "SELECT * FROM `users`.`info` WHERE username = '".$newUser."' ";
$queryResult = $con->query($query);
$result = mysqli_num_rows($queryResult);

if($result == 1)
{
echo $newUser." is already in use";
}

else
{
move_uploaded_file($_FILES["file"]["tmp_name"], "avatar/owner-".$_SESSION['username']."-fname-".$_SESSION['fname']."-l_name-".$_SESSION['lname']."-filename-".$_FILES["file"]["name"]);

//$updateQuery = "UPDATE `users`.`info` SET `username` = $newUser, `password` = $newPass, `contact_number` = $newConNum , `user_address` = $newAdd, `avatar_image_path` = $filepath WHERE `info`.`username` = '$username' AND `info`.`password` = '$userpass' AND `info`.`f_name` = '$firstname' AND `info`.`l_name` = '$lastname' AND `info`.`admin_level` = '$adminLvl' AND `info`.`contact_number` = '$ConNum' AND AND `info`.`user_address` = '$usrAdd' AND `info`.`avatar_image_path` = '$avaImgPth' ";

$updateQuery = " UPDATE `users`.`info` SET `username` = '$newUser',`password` = '$newPass',`f_name` = '$firstName',`l_name` = '$lastName',`contact_number` = '$newConNum',`user_address` = '$newAdd',`avatar_image_path` = '$filepath' WHERE `info`.`username` = 'username' AND `info`.`password` = 'userpass' AND `info`.`f_name` = 'firstName' AND `info`.`l_name` = 'lastName' AND `info`.`admin_level` =$adminLvl AND `info`.`contact_number` = '$ConNum' AND `info`.`user_address` = '$usrAdd' AND `info`.`avatar_image_path` = '$avaImgPth' ";

echo "Profile successfully UPDATED!";
}

}
?>

非常感谢您的回复。

最佳答案

您忘记执行查询。

    $updateQuery =" UPDATE  `users`.`info` SET  `username` =  '$newUser',`password` =  '$newPass',`f_name` =  '$firstName',`l_name` =  '$lastName',`contact_number` =  '$newConNum',`user_address` =  '$newAdd',`avatar_image_path` =  '$filepath' WHERE  `info`.`username` =  '$username' AND  `info`.`password` =  '$userpass' AND `info`.`f_name` =  '$firstName' AND  `info`.`l_name` =  '$lastName' AND  `info`.`admin_level` =$adminLvl AND  `info`.`contact_number` =  '$ConNum' AND  `info`.`user_address` =  '$usrAdd' AND `info`.`avatar_image_path` =  '$avaImgPth' ";

$excuteQuery = $con->query($updateQuery);

关于php - MYSQL UPDATE函数的正确使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22828800/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com