用PHP将图像和视频文件插入数据库

时间:2019-03-19 16:45:24

标签: php html sql

我正在尝试使用php将图像和视频文件插入数据库。 我有2个桌子,kurs和innhold。 我想将图像插入kurs表,并且它可以正常工作,当我尝试将视频插入innhold表时,它不起作用。这是我的代码: php代码:

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

    $kursId = $_POST['Id'];
    $tittel = $_POST['Tittel'];
    $info = $_POST['Info'];

    $kapittel = $_POST['Kapittel'];
    $intro = $_POST['Intro'];

    $dir = 'Pictures/';
    $bilde = $dir.basename($_FILES['Bilde']['name']);

    $mediadir = 'Media/';
    $video = $mediadir.basename($_FILES['Video']['name']);

    move_uploaded_file($_FILES['Bilde']['tmp_name'], $bilde);

    move_uploaded_file($_FILES['Video']['tmp_name'], $video);



    $leggkurs = "INSERT INTO kurs(Tittel, Info, Media) VALUES('$tittel', '$info', '$bilde')";
    $legginnhold = "INSERT INTO innhold(KursId, Tittel, Info, Innhold, PersonId) VALUES('$kursId', '$kapittel', '$intro', '$video', 1)";


    if ($conn->query($leggkurs) == TRUE && $conn->query($legginnhold) == TRUE) {
              $_SESSION['txt'] = 'Kurs lagt til!';
          } else {
              $_SESSION['txt'] = "Error updating record: $conn->error";
          }

}

html代码:

<div class="form-group">
  <div class="col-sm-12 col-md-6 col-lg-4 col-xl-3">
      <label class="control-label" for="Tittel"><b>Tittel</b></label>
    <input type="text" class="form-control" id="Tittel"  name="Tittel">
  </div>
</div>
<div class="form-group">
 <div class="col-sm-3"> 
     <label class="control-label" for="Info"><b>Info</b></label>
     <textarea type="text" class="form-control" id="Info"  name="Info"></textarea>
  </div>
</div>
<div class="form-group">
  <div class="col-sm-3">
      <label class="control-label" for="Bilde"><b>Bilde</b></label>
      <input type="file" class="form-control-file" id="Bilde"  name="Bilde">
  </div>
</div>
 <div class="form-group">
  <div class="col-sm-12 col-md-6 col-lg-4 col-xl-3">
      <label class="control-label" for="Kapittel"><b>Kapittel</b></label>
    <input type="text" class="form-control" id="Kapittel"  name="Kapittel">
  </div>
</div>
<div class="col-sm-3"> 
     <label class="control-label" for="Intro"><b>Intro</b></label>
     <textarea type="text" class="form-control" id="Intro"  name="Intro"></textarea>
</div>
<div class="form-group">
  <div class="col-sm-3">
      <label class="control-label" for="Video"><b>Video</b></label>
      <input type="file" class="form-control-file" id="Video"  value="Upload" name="Video">
  </div>
</div>   

  <button type="submit" class="btn btn-primary" name="Legg_Kurs" value="Submit" method="post" href="Admin.php">Legg til...</button>

那么我的代码有什么问题?

1 个答案:

答案 0 :(得分:0)

$ legginnhold =“将inert插入innhold(KursId,Tittel,信息,Innhold,PersonId)VALUES('$ kursId','$ kapittel','$ intro','$ video','1')”; < / p>

尝试一下