2013-01-23 38 views
0

更新記錄我上傳一些數據到包含標題,新聞日期和圖像的數據庫,但是當我想更新它我面臨的問題。基本上我想要做什麼我更新除圖像以外的所有行,然後更新不會發生。我基本上想要什麼時候我需要更新讓我們假設標題只有它應該更新它,但所有其他數據應該保持相同,但問題是,我不得不從我的電腦再次選擇圖像更新。我的情況是,我只保存在數據庫的名稱不整的路徑和硬編碼在以往任何時候我需要顯示的圖像圖像應保持不變更在php

這裏是HTML的路徑

<div class="row"> 
          <label>Image upload</label> 
          <div class="right"><input type="file" name="file" value="<?php echo $row['images'];?>" /></div> 
         </div> 

這裏是php

if(($_GET['mod']=='edit') && (isset($_POST['hidden']))) 
{ 




    echo $_FILES["file"]["name"]; 
     $allowedExts = array("jpg", "jpeg", "gif", "png"); 
     $extension = end(explode(".", $images)); 
     if ((($_FILES["file"]["type"] == "image/gif") 
     || ($_FILES["file"]["type"] == "image/jpeg") 
     || ($_FILES["file"]["type"] == "image/png") 
     || ($_FILES["file"]["type"] == "image/pjpeg")) 

     && in_array($extension, $allowedExts)) 
      { 
      if ($_FILES["file"]["error"] > 0) 
      { 

      echo $_FILES["file"]["error"] . "<br>"; 
      } 
      else 
      { 
      move_uploaded_file($_FILES["file"]["tmp_name"], "upload-images/" . $images); 
      $update="UPDATE headline SET 
               headline_title = '$title', 
               headline_des = '$description', 
               month   = '$month_name', 
               day    = '$day_name', 
               year   = '$year_name', 
               featured  = '$featured', 
               headline  = '$headline', 
               images   = '$images' 
               where id  = ".$_GET['id'].""; 
      $result = mysql_query($update);  

       } 
      } 
+0

想要分享一些片段來解釋你在做什麼和如何做? – ksg91

+0

我編輯的問題在提交更新用IMGE – user1885057

回答

0

再次提交表單將導致文件輸入的新值,這將是 所以你必須檢查它是否是空的或不是,並根據情況採取行動

例如

if($_FILES['file']['name'] != "") 
{ 
     //upload the image with what ever you want 
     //move_uploaded_file($_FILES['file']['tmp_name'],$target.$image); 
     //the SQL query should contain the updating the image column 
     if(($_GET['mod']=='edit') && (isset($_POST['hidden']))) 
     { 




echo $_FILES["file"]["name"]; 
    $allowedExts = array("jpg", "jpeg", "gif", "png"); 
    $extension = end(explode(".", $images)); 
    if ((($_FILES["file"]["type"] == "image/gif") 
    || ($_FILES["file"]["type"] == "image/jpeg") 
    || ($_FILES["file"]["type"] == "image/png") 
    || ($_FILES["file"]["type"] == "image/pjpeg")) 

    && in_array($extension, $allowedExts)) 
     { 
     if ($_FILES["file"]["error"] > 0) 
     { 

     echo $_FILES["file"]["error"] . "<br>"; 
     } 
     else 
     { 
     move_uploaded_file($_FILES["file"]["tmp_name"], "upload-images/" . $images); 
     $update="UPDATE headline SET 
              headline_title = '$title', 
              headline_des = '$description', 
              month   = '$month_name', 
              day    = '$day_name', 
              year   = '$year_name', 
              featured  = '$featured', 
              headline  = '$headline', 
              images   = '$images' 
              where id  = ".$_GET['id'].""; 
     $result = mysql_query($update);  

      } 
     } 
} 
else 
{ 
     //SQL update without image 
     $update="UPDATE headline SET 
              headline_title = '$title', 
              headline_des = '$description', 
              month   = '$month_name', 
              day    = '$day_name', 
              year   = '$year_name', 
              featured  = '$featured', 
              headline  = '$headline' 
              WHERE id  = ".$_GET['id'].""; 
     $result = mysql_query($update);  

} 

,如果你不想要的形象被簡單編輯可以從用於該或更新和表單中刪除它,但它在隱藏輸入的路徑

希望這將有助於

根據您的評論的查詢應該是這個樣子

 $update="UPDATE headline SET 
              headline_title = '$title', 
              headline_des = '$description', 
              month   = '$month_name', 
              day    = '$day_name', 
              year   = '$year_name', 
              featured  = '$featured', 
              headline  = '$headline' 
              WHERE id  = ".$_GET['id'].""; 
     $result = mysql_query($update);  

我認爲你需要使用良好的打算,使你的代碼在將來更易於閱讀和維護:)

+0

是給我空值,但我希望它得到分貝的形象,我在插入過程中插入,因爲這個時候,我不想改變形象,但只有標題或內容,如果你不 – user1885057

+0

t想要更改圖像,從查詢中刪除圖像字段 – Sedz

+0

現在檢查它..這是你想要的嗎? – Sedz