0

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.

4
  • I see following in your query 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? Commented Apr 3, 2014 at 5:49
  • what kind of error you getting Commented Apr 3, 2014 at 5:56
  • $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.. Commented Apr 3, 2014 at 6:08
  • @Lepanto, I just forgot to put $ but when I put them on. The result is still the same. The values are still not updating in the database. Commented Apr 3, 2014 at 6:42

1 Answer 1

2

You forgot to execute the query.

    $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);
Sign up to request clarification or add additional context in comments.

4 Comments

I added this $excuteQuery = $con->query($updateQuery); but still it doesn't update any information in the database.
Try to echo the query and execute it in database to check whether u r getting any sql errors.
"You forgot to execute the query with mysql_query()" --- OP is using mysqli_* functions.
Still nothing happens.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.