Home PHP Updating users table. I can update everything except image
Reply: 0

PHP Updating users table. I can update everything except image

cool ice
1#
cool ice Published in 2018-01-12 22:08:21Z

This question already has an answer here:

  • When to use single quotes, double quotes, and back ticks in MySQL 10 answers
  • Reference - What does this error mean in PHP? 30 answers

I made a login system which works perfectly. I have a webadmin system where i can update the users data everything also images. I have an user system like the user can be subscriber or admin, if the user is admin he can update every user's data. and if the user is subscriber he wont be able to access admin panel so i made a profile.php which can be accessed by the subscriber so he can change his own data if he wants. on profile.php i use a switch condition and at default state it includes view_profile.php its works nice because it shows the data for the user. also there is a button here called "Edit" if i click on it it changes the source and the same switch statement will include a file called edit_profile.php

It brings out everything good. The user is now able to set his own personal data. Like username email, firstname, lastname,password via click on the button called "Update" ( So its good because it is updating the data on the DATABASE also ). So afterall everything is good i wanted to create that to let the user change is image (profil picture) I made the index and added the image updating to the query also. When im uploading the picture and submit it moving the uploaded image to the right place etc.

After the update it changes the profile picture on the profile.php?source=edit_profile also the uploaded file is moved to the right place. ( checked it twice ) BUT THE PROBLEM IS THIS FUNCTION ISN'T UPDATING THIS IMAGE TO THE DATABASE. When i check on phpmyadmin users table it can be seen there is no change at user_image column. AND WHEN I REFRESH THE PAGE the older picture gets in the place again.

I HAVE TO MENTION IT IM USING SESSIONS ( you will see in the code where ) And i need a help about this to make the change into the database with the picture too.

first of all profile.php

<?php session_start(); ?>
<?php include "includes/header.php" ?>
<?php include "includes/db.php" ?>
<?php include "includes/navigation.php" ?>

    <!-- Page Content -->
<div style="background-color:transparent !important;" class="row">
    <div class="container">
         <div style="margin-top:8%;" class="col-md-8">

                     <?php   

                        if(isset($_GET['source'])){

                            $source=$_GET['source'];

                          } else {

                            $source='';
                            }
                            switch($source){


                                    case 'edit_profile';
                                     include "includes/edit_profile.php";
                                    break;



                                default: 

                               include "includes/view_profile.php";


                                    break;

                            }

                        ?>

            </div>

            <!-- Blog Sidebar Widgets Column -->
      <?php include "includes/sidebar.php" ?>



    </div>

</div>

    <?php include "includes/footer.php" ?>

the included view_profile.php on the default state ( where the profile data can be seen. im using session here just to mention )

 <?php 


    if(isset($_SESSION['username'])){
        $username = $_SESSION['username'];
        $query = "SELECT * FROM users WHERE username = '{$username}' ";
        $select_user_profile_query=mysqli_query($connection, $query);

        while($row = mysqli_fetch_array($select_user_profile_query)){
                 $user_id=$row['user_id'];
               $username=$row['username'];
               $user_password=$row['user_password'];
               $user_firstname=$row['user_firstname'];
               $role=$row['role'];
               $user_lastname=$row['user_lastname'];
               $user_email=$row['user_email'];
               $user_image=$row['user_image'];

        }


    } 
               ?>                  

                            <div class="row">


                              <div style="color:#333;padding:3rem;text-align:center; margin-top:140px;" class="bumm col-lg-8 col-md-8 col-sm-7 col-xs-12"> 
                                                 <div style="text-align:center;" class="col-lg-12 col-md-12 col-sm-12 col-xs-12"> 
                                                                 <div style="padding-bottom:1.5rem;display: flex; justify-content: center;">



    <?php  echo "<img src='images/users_folder/$user_image' style='border-radius:50%;box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.5); width:100px; height:100px; /* Safari 6.0 - 9.0 */ ' />";      ?>


      </div> 
                             <div  style="background-color:whitesmoke !important;font-family: 'Quicksand', sans-serif;padding-top:6rem;margin-top:-60px;box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.5);" class="well">
                                <p style="text-align:justify;"> <label style="text-align:justify;" for="username">Name : <?php echo $user_firstname . " " . $user_lastname; ?></label> </p> 
                               <p style="text-align:justify;"> <label style="text-align:justify;" for="username">Username : <?php echo $username; ?></label></p> 
                             <p style="text-align:justify;"> <label style="text-align:justify;" for="username">Role : <?php echo $role; ?></label></p> 
                              <p style="text-align:justify;"> <label  for="username">Email : <?php echo $user_email; ?></label></p> 
                               <h4 style="display:inline-block !important">   <a class="" style="text-align:left !important; padding:0.55rem !important;font-family: 'Quicksand', sans-serif; text-decoration:none !important; color:#333 !important;" href='profile.php?source=edit_profile' class="">Edit</a></h4> 
                        </div>

                      </div>
                 </div>
           </div>

The last the included edit_profile.php where the problem is i think. a bit long because of the form sorry

 <?php 

    if(isset($_SESSION['username'])){
        $username = $_SESSION['username'];
        $query = "SELECT * FROM users WHERE username = '{$username}' ";
        $select_user_profile_query=mysqli_query($connection, $query);

        while($row = mysqli_fetch_array($select_user_profile_query)){
                $user_id=$row['user_id'];
               $username=$row['username'];
               $user_password=$row['user_password'];
               $user_firstname=$row['user_firstname'];
               $user_lastname=$row['user_lastname'];
               $user_email=$row['user_email'];
               $user_image=$row['user_image'];

        }
    }   
               ?>  
<?php 

    if(isset($_POST['edit_user'])){

               $user_firstname=$_POST['user_firstname'];
               $user_lastname=$_POST['user_lastname'];
               $username=$_POST['username'];
               $user_email=$_POST['user_email'];
               $user_password=$_POST['user_password'];
                      $user_image=$_FILES['user_image']['name'];
             $user_image_temp=$_FILES['user_image']['tmp_name'];

               move_uploaded_file($user_image_temp, "images/users_folder/$user_image");


          $query = "UPDATE users SET ";
             $query .= "user_firstname = '{$user_firstname}', ";
             $query .= "user_lastname = '{$user_lastname}', ";
             $query .= "user_image = '{$user_image}', ";
             $query .= "username = '{$username}', ";
             $query .= "user_email = '{$user_email}', ";
             $query .= "user_password = '{$user_password}' ";
             $query .= "WHERE username = {$username} ";
             $edit_user_query = mysqli_query($connection,$query);

              }
       ?>                                                                                         
                          <form style="" action="" enctype="multipart/form-data" method="post" class="action">                                                                                                                                                                                                    

                      <div class="row">

                              <div style="color:#333;padding:3rem;text-align:center; margin-top:30px;" class="bumm col-lg-8 col-md-8 col-sm-7 col-xs-12"> 
                                                 <div style="text-align:center;" class="col-lg-12 col-md-12 col-sm-12 col-xs-12"> 
                                                                 <div style="padding-bottom:1.5rem;display: flex; justify-content: center;">                                                                                                                                                                                                                                                                              
    <?php  echo "<img src='images/users_folder/$user_image' style='border-radius:50%;box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.5); width:100px; height:100px; /* Safari 6.0 - 9.0 */ ' />";      ?>

      </div> 
                             <div  style="background-color:whitesmoke !important;font-family: 'Quicksand', sans-serif;padding-top:6rem;margin-top:-60px;box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.5);" class="well">
                              <div class="form-group">
        <label for=""> Image </label>
        <input type="file" class="form-control" value="<?php echo $user_image; ?>" name="user_image">
        </div>

                                <p style="text-align:justify;"> <label style="text-align:justify;" for="user_firstname">Firstname :  <input type="text" value="<?php echo $user_firstname; ?>" style="width:100%;" class="form-control" name="user_firstname">   </label> </p> 
                               <p style="text-align:justify;"> <label style="text-align:justify;" for="user_lastname">Lastname :  <input type="text" value="<?php echo $user_lastname; ?>" style="width:100%;" class="form-control" name="user_lastname"> </label></p> 
                             <p style="text-align:justify;"> <label style="text-align:justify;" for="username">Username :  <input type="text" value="<?php echo $username; ?>" style="width:100%;"  class="form-control" name="username"> </label></p> 
                              <p style="text-align:justify;"> <label  for="username">Email :  <input type="email"  value="<?php echo $user_email; ?>" style="width:100%;"  class="form-control" name="user_email"> </label></p> 
                               <p style="text-align:justify;"> <label  for="username">Password :  <input type="text" style="width:100%;" value="<?php echo  $user_password; ?>" class="form-control" name="user_password"> </label></p> 
                        <div class="form-group">   

        <input style="background-color:white !important;color:#333;" class="" type="submit" name="edit_user" value="Update user">
                                 </div>
                                    <div class="form-group">   

        <a href="profile.php">Go back to profil page</a>
                                 </div>
                        </div>  
                        </div>
                          </div>
                           </div>       
         </form>     
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.341778 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO