I am using MySQL query to UPDATE the information in the database.
I tried updating the information from the localhost/phpmyadmin and later on copy the code that was given in the localhost/phpmyadmin.
The problem is that the information/values are not updating in the database.
Below is the code:
<?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!";
}
}
?>
Thank you so much for your response.
WHERE info.username = 'username' AND info.password = 'userpass' AND info.f_name = 'firstName' AND info.l_name = 'lastName' AND..., username, userpass and other string are they not a variable? is$missing there?$executeUpdate = mysql_query( $updateQuery, $con);you should try this and refer this link (tutorialspoint.com/mysql/mysql-update-query.htm) and you should must check db connection is working or not..$but when I put them on. The result is still the same. The values are still not updating in the database.