<?php
            if(isset($_SESSION['id']) ) {
            ($_SESSION['id']) {
                //echo "you're login";
            }
                echo "<form action='upload.php' enctype='multipart/form-data' method='post'>
                    <br>Qr Code:
                    <p><input type='file' name='file' >
                    <p><input type='submit' value='Upload' name='submit'>
                      </form>";
                            }
                ?>
 <?php
                $statusMsg = '';
                // File upload path
                $targetDir = "qr_code/";
                $fileName = basename($_FILES["file"]["name"]);
                $targetFilePath = $targetDir . $fileName;
                $fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION);
                if(isset($_POST["submit"]) && !empty($_FILES["file"]["name"])){
                    // Allow certain file formats
                    $allowTypes = array('jpg','png','jpeg','gif','JPG','PNG','GIF','JPEG');
                    if(in_array($fileType, $allowTypes)){
                        // Upload file to server
                        if(move_uploaded_file($_FILES["file"]["tmp_name"], $targetFilePath)){
                            // Insert image file name into database
                            $insert = $db->query("INSERT into qr (user_id,file_name, uploaded_on) 
                                        VALUES ('".$_SESSION['id']."','".$fileName."', NOW())");
                            if($insert){
                                $statusMsg = "The file ".$fileName. " has been uploaded successfully.";
                                    header ("Location:employee.php?uploadsuccess");
                            }else{
                                $statusMsg = "File upload failed, please try again.";
                            }
                        }else{
                            $statusMsg = "Sorry, there was an error uploading your file.";
                        }
                    }else{
                        $statusMsg = 'Sorry, only JPG, JPEG, PNG, GIF files are allowed to upload.';
                    }
                }else{
                    $statusMsg = 'Please select a file to upload.';
                }
                // Display status message
                echo $statusMsg;
                ?>

<?php
                     $query = $db->query("SELECT * FROM qr where user_id='".$_SESSION['id']."' ORDER BY uploaded_on DESC limit 1 ");
                        if($query->num_rows > 0){
                            while($row = $query->fetch_assoc()){
                                $imageURL = 'qr_code/'.$row["file_name"];
                        ?>
                            <img src="<?php echo $imageURL; ?>" alt="" />
                        <?php }
                        }else{ ?>
                              <img src="images/qr.png" alt="" />

                    <?php } ?>

I have Two IDs user and employee
The employee will upload the image for the user but the display of image for the user won't show up since they have Two different IDs

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.