2012-06-15 87 views
-1

查詢不更新數據庫

​​

我的表單代碼爲

<input type="file" name="image" value="<?php echo $row['image']; ?>" /> 
+0

我修改了標題,因爲代碼不是 「加載圖像」 - 您要舉報的麻煩更新你的數據庫。請包括您的表單代碼,以便我們看到。 –

+0

我的表單代碼是 」/> –

回答

3
  1. 您執行查詢
  2. 有一個額外的支架(這可能只是一個錯字或完全另外一個問題)
  3. 之前調用 exit()
+0

它只是用於回聲的目的,但仍然不起作用。 – leoabbasi

+0

我有更新的代碼,請檢查並回答謝謝... – leoabbasi

+0

mysql_error()說什麼? –

1

它來檢查r是重要的爲您「做」某些功能的功能。假設是這樣,你要確保在前進之前確實完成了它。無論move_uploaded_filemysql_query威力失敗。

如果他們這樣做,他們就會讓你知道它們的返回值(通常爲布爾FALSE)。捕獲並返回並做出適當的反應。那麼,如果出現問題,你不必爲了找出原因而撓頭。

$img_src = '/assuming/some/path/'; 
$img = false; 
$error = false; 
if (
    isset($_FILES['image']) && 
    $_FILES['image']['error'] != 4 
) { 
    $img = $_FILES['image']; 
    switch ($img['error']) { 
     case '1': 
     case '2': 
     case '3': 
      $error = 'The uploaded file exceeds the maximum file size.'; 
      break; 
     case '6': 
     case '7': 
     case '8': 
      $error = 'Server error. Please try again later.'; 
      break; 
    } 
    if (!$error) { 
     $imgnew = date("YmdHis").".".end(explode('.',$img['name'])); 
     $result = move_uploaded_file($img['tmp_name'],$img_src.$imgnew); 
     if (!$result) 
      $error = 'File error while processing upload'; 
    } 
    if (!$error) { 
     $sql = "UPDATE news SET `image` = '".$imgnew."' WHERE `id` = '".$id."'"; 
     $result = mysql_query($sql); 
     if (!$result) 
      $error = mysql_error(); 
    } 
} 

// do something useful with the error message, preferrably not this 
if ($img && $error) 
die('There was a problem updating the image: '.$error); 

文檔

PHP的move_uploaded_file - http://us2.php.net/manual/en/function.move-uploaded-file.php

PHP的mysql_query - http://us2.php.net/manual/en/function.mysql-query.php