如何使用MYSQL更新现有映像

时间:2019-06-05 22:49:06

标签: php mysql

我正在尝试使用mysql查询更新数据库中的现有映像。

这是我的edit.php,我在其中编辑用户信息

<?php
  require_once "config.php";

    if(isset($_GET['edit']))
    {
        $id = $_GET['edit'];
        $res = mysqli_query($link,"SELECT * FROM user_data WHERE id=$id");
        $row = mysqli_fetch_array($res);
    }

    if(isset($_GET['id']))
    {
      $newText = $_GET['voornaam'];
      $newText2 = $_GET['tussenvoegsel'];
      $newText3 = $_GET['achternaam'];
      $newText4 = $_GET['stemsoort'];
      $newText5 = $_GET['adres'];
      $newText6 = $_GET['postcode'];
      $newText7 = $_GET['plaats'];
      $newText8 = $_GET['telefoon'];
      $newText9 = $_GET['mobiel'];
      $newText10 = $_GET['email'];
      $newText11 = $_GET['status'];
      $newText12 = $_GET['lid_sinds'];
      $newText13 = $_GET['lid_tot'];

      $id    = $_GET['id'];
      $res = mysqli_query($link,"SELECT * FROM user_data WHERE id=$id");
      $row = mysqli_fetch_array($res);
      $sql     = "UPDATE user_data SET voornaam='$newText', tussenvoegsel='$newText2', achternaam='$newText3', stemsoort='$newText4', adres='$newText5', postcode='$newText6', plaats='$newText7', telefoon='$newText8', mobiel='$newText9', email='$newText10', status='$newText11',lid_sinds='$newText12',lid_tot='$newText13' WHERE id=$id";
      $res   = mysqli_query($link,$sql)
                                      or die("Could not update".mysqli_error($link));
        echo "<meta http-equiv='refresh' content='0;url=index.php'>";
    }
  ?>

这是我将图像上传到文件夹然后再上传到mysql数据库的方式

 <?php

  $msg = "";
  $css_class = "";

  $conn = mysqli_connect('localhost','root','','test');

  if (isset($_POST['save-user'])) {
    echo "<pre>", print_r($_FILES['profileImage']['name']),"</pre>";

    $bio = $_POST['bio'];
    $profileImageName = time() . '_' . $_FILES['profileImage']['name'];

    $target = 'images/' . $profileImageName;

      if(move_uploaded_file($_FILES["profileImage"]["tmp_name"], $target)) {
        $sql = "INSERT INTO users (profile_image, bio) VALUES ('$profileImageName','$bio')";
        if (mysqli_query($conn,$sql)) {
          $msg = "image uploaded";
          $css_class = "alert alert-success";
        }else {
          $msg = "Database Error: Failed to save user";
          $css_class = "alert alert-danger";
        }
      } else {
        $msg = "Failed to upload image";
        $css_class = "alert alert-danger";
      }
    }

 ?>

我如何结合两者,让用户编辑他上传的个人资料图片?感谢您的帮助

0 个答案:

没有答案