使用UPDATE不会将图像加载到我的数据库中

时间:2019-03-27 14:00:35

标签: php mysql forms image

我有一个将图像加载到本地“上载”文件夹的表单,因此我知道该部分有效。但是,该表单也应该将图像加载到用户表-头像字段,但是当我检查用户表时没有图像。

我使用users.php来添加和更新图像。

<?php
include('..config/connection.php');

$ds = DIRECTORY_SEPARATOR;  //1
$id = $_GET['id'];

$storeFolder = '../uploads';   //2

$name = 'image'.'_'.date('Y-m-d-H-i-s').'_'.uniqid().'.jpg';

$q = "UPDATE users SET avatar = '$name' WHERE id = $id";
$r = mysqli_query($dbc, $q);

if (!empty($_FILES)) {

    $tempFile = $_FILES['file']['tmp_name'];          //3             

    $targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds;  //4

   // $targetFile =  $targetPath. $_FILES['file']['name'];  //5

    $targetFile =  $targetPath. $name;  //5

    move_uploaded_file($tempFile,$targetFile); //6

}

user.php还应该显示更新的图像-与用户相关联。

<?php if (isset($opened['id'])) { ?>
    <script>

        $(document).ready(function() {
            Dropzone.autoDiscover = false;
            var myDropzone = new Dropzone("#avatar-dropzone");
        });

    </script>
<?php } ?>

<h1>User Management</h1>

<div class="row">...

divs and other stuff
 ....   

        <!-- form section-->    
        <form action="index.php?page=users&id=<?php echo $opened['id']; ?>" method="post" role="form">

            <?php if($opened['avatar'] != '') { ?>

                <img src="../uploads/<?php echo $opened['avatar']; ?>"

            <?php } ?>

            <div class="form-group">
            <label for="first">First Name</label>
            <input type="text" class="form-control" id="first" value="<?php echo $opened['first']; ?>" name="first" placeholder="First Name" autocomplete="off">
            </div>

            <div class="form-group">
            <label for="last">Last Name</label>
            <input type="text" class="form-control" id="last" value="<?php echo $opened['last']; ?>" name="last" placeholder="Last Name" autocomplete="off">
            </div>

            <div class="form-group">
            <label for="email">Email</label>
            <input type="text" class="form-control" id="email" value="<?php echo $opened['email']; ?>" name="email" placeholder="Email" autocomplete="off">
            </div>

            <div class="form-group">
            <label for="status">Status</label>
            <select class="form-control" id="status" name="status">
            <option value="0" <?php if (isset($_GET['id'])) { selected('0', $opened['status'], 'selected'); } ?>>Inactive</option>
            <option value="1" <?php if (isset($_GET['id'])) { selected('1', $opened['status'], 'selected'); } ?>>Active</option>
            </select>
            </div>

            <div class="form-group">
            <label for="password">Password</label>
            <input type="password" class="form-control" id="password" value="" name="password" placeholder="Password" autocomplete="off">
            </div>

            <div class="form-group">
            <label for="passwordv">Verify Password</label>
            <input type="password" class="form-control" id="passwordv" value="" name="passwordv" placeholder=" Type Password Again" autocomplete="off">
            </div>

            <button type="submit" class="btn btn-default">Save</button>

            <input type="hidden" name="submitted" value="1">
            <?php if (isset($opened['id'])) { ?>
            <input type="hidden" name="id" value="<?php echo $opened['id']; ?>">
            <?php } ?>
        </form>

        <?php if (isset($opened['id'])) { ?>

            <!--dropzone form -->
            <form action="uploads.php?id=<?php echo $opened['id']; ?>" class="dropzone" id="avatar-dropzone">
              <div class="fallback">
                <input name="file" type="file" />
              </div>
            </form>

        <?php } ?>

    </div><!-- col-md-09 end -->

</div><!-- row end -->

我想念什么,但是呢?

0 个答案:

没有答案
相关问题