我试图在我的页面上的每个食谱旁边都有一个上传按钮,因此我需要在图像上传期间传递食谱 ID 值,以便图像路径保存在我数据库中的每个食谱旁边。但由于某些原因,我不断收到同样的错误:
Notice: Undefined index: recipe_id in C:\xampp\htdocs\upload.php on line 4
第 4 行是:$recipe_id = $_POST['recipe_id'];
这是 HTML 表单:
<div class="upload_icon">
<form id="<?php echo $recipe_id ?>" action="upload.php" method="POST"
enctype="multipart/form-data">
<input type="file" name="image" value="<?php echo $recipe_id ?>"/></input>
<button type="submit" name="submit" value="add">Add image!</button>
</form>
</div>
PHP部分(upload.php):
if ($_SERVER["REQUEST_METHOD"] == "POST");
{
$recipe_id = $_POST['recipe_id'];
$name = $_FILES ['image'] ['name'];
$tmp_name = $_FILES ['image'] ['tmp_name'];
$location = "uploads/$name";
move_uploaded_file($tmp_name, $location);
$update = query("UPDATE menu SET recipe_pic = '".$location."' WHERE recipe_id =
'$recipe_id' " );
}
?>
我究竟做错了什么?