「未定義指數:圖像中 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> </td>
<td> </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> </td>
<td> </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> </td>
<td> </td>
</tr>
<tr>
<td height="37"><b>Image:</b></td>
<td><input type="file" name="image" id="image"></td>
</tr>
<tr>
<td> </td>
<td> </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> </td>
<td> </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";
}
} //}
}
}
what's的print_r($ _ FILES)的'輸出;'? – panther
它顯示陣列()........ print_r的 – user3733306