2014-06-12 102 views
0

「未定義指數:圖像中 C:\ XAMPP \ htdocs中\ learn_php \在線路34上分類\ insertup.php」 這個錯誤 被示出,並且線34是 -

$path= "Image/".$_FILES["image"]["name"]; 

EDIT.PHP文件: -

<?php 
if(isset($_GET['id']) && $_GET['id'] != '') { 
mysql_connect('localhost', 'root', ''); 
mysql_select_db('opencart_php'); 
    $id=$_GET['id']; 

$query=mysql_query("SELECT * FROM categories WHERE Id='".$id."'"); 
    $row=mysql_fetch_array($query); 
    $cname = $row['category_name']; 
    $sname = $row['sort_order']; 
    $desc = $row['description']; 
    $image = $row['image']; 
} else { 
    $id = ''; 
    $cname = ''; 
    $sname = ''; 
    $desc = ''; 
    $image = ''; 
} 
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
<title>Category Details</title>` 
<h1 align="center">Category Details</h1> 
</head> 

<body> 
<table width="400" border="1" align="center"> 
<tr> 
<td><form name="myform" action="insertup.php?id=<?php echo $id; ?>" method="post" enctype="multipart/form_data"> 
<table width="334" border="0" align="center"> 
    <tr> 
    <td><b>Category Name:</b></td> 
    <td><input type="text" name="cname" value="<?php echo $cname; ?>"></td> 
    </tr> 
    <tr> 
    <td>&nbsp;</td> 
    <td>&nbsp;</td> 
    </tr> 
    <tr> 
    <td><b>Sort Order:</b></td> 
    <td><input type="text" name="sorder" size="5" value="<?php echo $sname; ?>"></td> 
    </tr> 
    <tr> 
    <td>&nbsp;</td> 
    <td>&nbsp;</td> 
    </tr> 
    <tr> 
    <td height="40"><b>Description:</b></td> 
    <td><input type="text" rows="10" cols="20" name="desc" value="<?php echo $desc; ?>" /></td> 
    </tr> 
    <tr> 
    <td>&nbsp;</td> 
    <td>&nbsp;</td> 
    </tr> 
    <tr> 
    <td height="37"><b>Image:</b></td> 
    <td><input type="file" name="image" id="image"></td> 
    </tr> 
    <tr> 
    <td>&nbsp;</td> 
    <td>&nbsp;</td> 
    </tr> 
    <tr> 
    <td><b>Status:</b></td> 
    <td><select name="status"> 
      <option value='1'>Enable</option> 
      <option value='0'>Disable</option> 
     </select></td> 
    </tr> 
    <tr> 
    <td>&nbsp;</td> 
    <td>&nbsp;</td> 
    </tr> 
</table> 
<table width="368"> 
<tr> 
<td width="173" align="right"><input type="submit" name="submit" value="Submit"></td> 
<td width="183" align="center"><input type="reset" name="reset" value="Reset"></td> 
</tr> 
</table> 
</form></td> 
</tr> 
</table> 
</body> 
</html> 

INSERTUP.PHP: -

if($_POST["cname"] != "" && $_POST["desc"] != "" && $_POST["image"] != "") { 
     $_SESSION['cname']=$_POST["cname"]; 
     //echo $_SESSION['cname']; 
     $query=mysql_query("SELECT * FROM categories WHERE category_name='".$_SESSION['cname']."'"); 
     $row=mysql_fetch_array($query); 
     $c_name=$row['category_name']; 
     $img=$row['image']; 
     echo $c_name; 
     //$id=$row['id']; 
     //if(isset($_FILES["image"])) { 
     print_r($_FILES); 
      if($cname != $c_name && $image != $img) { 
       $path= "Image/".$_FILES["image"]["name"]; 
       if($path != '') { 
        if(copy($_FILES["image"]["tmp_name"], $path)) { 
         $sql=mysql_query("INSERT INTO categories (category_name, sort_order, description, image, status) 
          VALUES ('$cname', '$sorder', '$desc', '$image', '$status')") or die(mysql_error()); 
         header('location: index.php'); 
        } else { 
        echo "Error in Insertion"; 
        } 
       } else { 
        echo "Image not Uploaded"; 
       } 
      } //} 
    } 
} 
+2

what's的print_r($ _ FILES)的'輸出;'? – panther

+0

它顯示陣列()........ print_r的 – user3733306

回答

0

在HTML中有(form-data)

變化

<form name="myform" action="insertup.php?id=<?php echo $id; ?>" method="post" enctype="multipart/form_data"> 

<form name="myform" action="insertup.php?id=<?php echo $id; ?>" method="post" enctype="multipart/form-data"> 
+0

後並未奏效...... – user3733306

+0

什麼是不工作?您是否正在做的print_r($後)的$ _FILES – Anish

0

在你的HTML中的錯字,在form必須是enctype="multipart/form-data",不是enctype="multipart/form_data"

<form name="myform" action="insertup.php?id=<?php echo $id; ?>" method="post" enctype="multipart/form-data"> 

然後,$_POST['image']上的insertup.php 1線你的病情很可能是空的,所以它改成

if($_POST["cname"] != "" && $_POST["desc"] != "" && !empty($_FILES["image"]["name"])) { 
+0

值混得insertup.php值不是從edit.php頁移動到頁面insertup.php ...... plz幫助 – user3733306

+0

如果固定'ENCTYPE 'attr,並且文件輸入真的有'name = image',它應該可以工作。 – panther