2013-02-01 27 views
-1

,否則Sql更新不起作用,我必須選擇相同的圖片文件或其他圖片文件才能更新這些行。但我希望能夠在不觸及其他行的情況下更改我想要的內容。任何想法在這裏?除非在這個編輯文件中選擇一個上傳文件

<?php 

include ("../header.php"); 
include ("../header2.php"); 

?> 
<?php 
include('../config.php'); 
include ('../ac.thumbs.php'); 

if ($_GET['sil']) { 
    $sil = htmlspecialchars(stripslashes($_GET['sil'])); 

    mysql_query("DELETE FROM CloseOut WHERE itemNO = $sil limit 1"); 
    echo "<h1>$sil item nolu kayit silinmistir</h1><br>"; 
} 

    $edit = htmlspecialchars(stripslashes($_GET['edit'])); 
    //Resimlerin yuklenecegin yer 
$target = "../../upload/"; 
////////////////////////////////////////////////////////////////////// 
///////////////////////////////Resim1///////////////////////////////// 
////////////////////////////////////////////////////////////////////// 
$target1 = $target . basename($_FILES['resim1']['name']) ; 
//Formdan gelen bilgileri almasi icin 
$resim=($_FILES['resim1']['name']); 
$isim=$_POST['isim1']; 
$alan1=$_POST['alan11']; 
$alan2=$_POST['alan21']; 
$alan3=$_POST['alan31']; 
$alan4=$_POST['alan41']; 



/////////////Formdaki bos alanlara bos bilgi kayit etmemesi icin//////////////////////// 

$updates = array(); 
if (!empty($resim)) 
    $updates[] = 'resim="'.mysql_real_escape_string($resim).'"'; 
if (!empty($isim)) 
    $updates[] = 'isim="'.mysql_real_escape_string($isim).'"'; 
if (!empty($alan1)) 
    $updates[] = 'alan1="'.mysql_real_escape_string($alan1).'"'; 
if (!empty($alan2)) 
    $updates[] = 'alan2="'.mysql_real_escape_string($alan2).'"'; 
if (!empty($alan3)) 
    $updates[] = 'alan3="'.mysql_real_escape_string($alan3).'"'; 
if (!empty($alan4)) 
    $updates[] = 'alan4="'.mysql_real_escape_string($alan4).'"'; 
$updates = implode(', ', $updates); 


///////////////////////////////////////////////////////////////////////////////////////// 
//update etmesi icin 
if(move_uploaded_file($_FILES['resim1']['tmp_name'], $target1)) 
{ 
mysql_query("UPDATE CloseOut SET $updates WHERE itemNO='$edit' "); 
echo "Tebrikler, ". basename($_FILES['resim1']['name']). " isimli dosya yuklendi ve database'e basariyla islendi!<br>"; 
} 




$data = mysql_query("SELECT * FROM CloseOut WHERE itemNO=$edit") or die(mysql_error()); 

//Puts it into an array 
while($info = mysql_fetch_array($data)) 
{ echo " 
<center> 
<a href=\"edit.php?sil=$info[itemNO]\"onclick=\"return confirm('Do you really want to erase this entry?')\">[ Delete ]</a><br> 
<a href=../../large.php?f=upload/".$info['resim'], $thumblarge ."> 
<img src=../../small.php?f=upload/".$info['resim'], $thumbsmall ."> 
</a>"; 
$editresim = $info[resim]; 
$editisim = $info[isim]; 
$editalan1 = $info[alan1]; 
$editalan2 = $info[alan2]; 
$editalan3 = $info[alan3]; 
$editalan4 = $info[alan4]; 
} 


?> 

<br> 
<center> 
<table width="900" border="5" style="background-color:white; "bordercolor="#000000"> 
    <tr> 
     <td width="120" height="50" bgcolor= "545454"><b>RESIM</b></td> 
     <td width="120" height="50" bgcolor= "545454"><b>NAME</b></td> 
     <td width="120" height="50" bgcolor= "545454"><b>CATAGORY</b></td> 
     <td width="120" height="50" bgcolor= "545454"><b>QUANTITY</b></td> 
     <td width="120" height="50" bgcolor= "545454"><b>LOCATION</b></td> 
     <td width="120" height="50" bgcolor= "545454"><b>PRICE</b></td> 
    </tr> 
    <tr> 
<form enctype="multipart/form-data" method="post" action=""> 
<td><input type="file" name="resim1" value="<?php echo $editresim;?>"> </td> 
<td><input type="text" name="isim1" value="<?php echo $editisim;?>"> </td> 
<td><input type="text" name="alan11" value="<?php echo $editalan1;?>"> </td> 
<td><input type="text" name="alan21" value="<?php echo $editalan2;?>"> </td> 
<td><input type="text" name="alan31" value="<?php echo $editalan3;?>"></td> 
<td><input type="text" name="alan41" value="<?php echo $editalan4;?>"></td> 
</tr> 

<td colspan="6"><center><input type="submit"></center></td> 


</form> 
</table> 
</center> 

回答

1

看看這段代碼:

if(move_uploaded_file($_FILES['resim1']['tmp_name'], $target1)) 
{ 
    mysql_query("UPDATE CloseOut SET $updates WHERE itemNO='$edit' "); 
    echo "Tebrikler, ". basename($_FILES['resim1']['name']). " isimli dosya yuklendi ve database'e basariyla islendi!<br>"; 
} 

如果你不上傳任何東西,然後move_uploaded_file將會返回false,你的更新將永遠不會發生。

+0

所以我只需要找出一個代碼,說如果沒有上傳文件,然後忽略move_uploaded_file?會解決嗎? – Coderwannabe

+0

您需要在有或沒有上傳文件的情況下對更新運行查詢。 – datasage

+0

即時通訊對不起,我真的在開始階段即時消息不完全理解..請你儘可能少具體。 – Coderwannabe

相關問題