2015-06-26 47 views
0

我使用class.upload.php制作了一个简单的上传系统,它在向数据库中添加新内容时效果很好。但是当我需要编辑我的条目时,我遇到了问题。虽然编辑条目我不想编辑图像,但它发送空白,如果我再次选择图像它也发送它空白。这是我的代码。使用class.upload.php编辑上传的图像

可以解释我的问题。

<?php require_once("conn.php"); 
require_once ("class.upload.php"); 

$catid = $_POST['catid']; 
$title = $_POST['title']; 
$descc = $_POST['descc']; 
$keyw = $_POST['keyw']; 
$message = $_POST['message']; 
$Image = $_FILES['Image']; 
$randnum = rand(); 
$foo = new upload($Image); 
$filee = './Image'; 
if ($foo->uploaded) { 
$foo->image_resize = true; 
$foo->file_new_name_body = $randnum; 
$foo->image_x = 550; 
$foo->image_y = 440; 
$foo->process($filee); 
if ($foo->processed) { 
echo 'Image uploaded.'; 
echo $foo->file_dst_name; 
$foo->clean(); 
} else { 
echo 'Error. : ' . $foo->error; 
} 
} 
$Image7 = $foo->file_dst_name; 
    if($_GET[pass] == 1) 
    { 
     if(!isset($_POST[catid]) || empty($_POST[catid])){ 
      $hata = "Required area."; 
     } 
     if(!isset($_POST[title]) || empty($_POST[title])){ 
      $hata = "Required area."; 
     } 
     if(!isset($_POST[descc]) || empty($_POST[descc])){ 
      $hata = "Required area."; 
     }  
     if(!isset($_POST[keyw]) || empty($_POST[keyw])){ 
      $hata = "Required area."; 
     } 
     if(!isset($_POST[message]) || empty($_POST[message])){ 
      $hata = "Required area."; 
     } 
     if(!$hata){ 
      mysql_query("UPDATE product SET 
       catid='$_POST[catid]', 
       title='$_POST[title]', 
       descc='$_POST[descc]', 
       keyw='$_POST[keyw]', 
       message='$_POST[message]', 
       Image='$_POST[Image]' 
       WHERE id='$_POST[id]' 
       "); 
      $mesaj = "OK!"; 
     } 

    } 
    $sonuc = mysql_query("select * from product WHERE id='$_GET[product]'"); 
    $edit = mysql_fetch_array($sonuc); 
    $sonuc1 = mysql_query("select * from category"); 
    $edit1 = mysql_fetch_array($sonuc1); 
?> 
+0

其简单的只是删除图片= '$ _ POST [图片]' 从你的更新查询。 –

+0

如果我删除,我不能编辑图像,谢谢你的回答:) –

+0

在这种情况下,数据库需要图像字段。您需要将其从NOT NULL更改为NULL。 –

回答

0

尝试改变更新查询

在图像= '$ _ POST [图片]'

与图片= '$ Image7'

+0

你好,谢谢你的回答。我尝试过,如果我在编辑时再次选择图像,但是如果我不选择图像并编辑其他部分,图像会中断。我想如果我不选择任何图像,它不会更改图像列。我希望我能解释 –

0

法提赫你可以使用一个变量(即$ saved_image_name)而不是$ sql [查询]。如果上传其他旧字段的值,则将此变量设置为新名称。

... 
... 
$foo = new upload($Image); 
$filee = './Image'; 

$saved_image_name = " Image "; // name of db field. 

if ($foo->uploaded) { 
$foo->image_resize = true; 
$foo->file_new_name_body = $randnum; 
$foo->image_x = 550; 
$foo->image_y = 440; 
$foo->process($filee); 
if ($foo->processed) { 
echo 'Image uploaded.'; 
echo $foo->file_dst_name; 
// Note the quotes 
$saved_image_name = " '$foo->file_dst_name' "; 
$foo->clean(); 
} else { 
echo 'Error. : ' . $foo->error; 
} 
} 
// no use anymore $Image7 = $foo->file_dst_name; 
... 
... 

if(!$hata){ 
      mysql_query("UPDATE product SET 
       catid='$_POST[catid]', 
       title='$_POST[title]', 
       descc='$_POST[descc]', 
       keyw='$_POST[keyw]', 
       message='$_POST[message]', 
       Image= $saved_image_name // note the quotes 
       WHERE id='$_POST[id]' 
       "); 

... ...