【发布时间】:2016-01-28 14:54:06
【问题描述】:
创建一个应该展示几个不同电视节目的小型网站。我有一个页面应该允许用户输入新的电视节目名称和电视节目的图片。
由于某种原因,我在第 41、44、45 和 52 行遇到未定义索引错误。代码如下:
<form action="upload.php" method="POST" enctype="multipart/form-data">
Programme Title: <input type="text" name="title"> </br>
Select photo to upload:<input type="file" name="photo" id="photo"> <br/>
<input type="submit" value="Upload" name="submit">
</form>
<?php
//This is the directory where images will be saved
$target = "images/";
$target = $target . basename( $_FILES['photo']['name']); --- ERROR line 41
//This gets all the other information from the form
$title=$_POST['name']; --- ERROR line 44
$pic=($_FILES[' ']['name']); --- ERROR line 45
//Writes the information to the database
mysqli_query($mysqli, "INSERT INTO programmes VALUES ('', '$title', '', '$pic')") ;
//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) --- ERROR line 52
{
//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>
错误信息:
未定义索引:照片在 C:\wamp\www\sky_coding\upload.php 上线 45、49 和 55 未定义索引:标题在 C:\wamp\www\sky_coding\upload.php 在第 48 行
请帮忙 我很困惑,不知道为什么会出现这个错误
任何信息都会有所帮助 谢谢!
【问题讨论】:
-
请标出线条。
-
@NiranjanNRaju 如何标记线条?
-
只需在 cmets 中写一行,例如
error line -
我已经更新了帖子
-
当您编写有关错误的问题时,总是包含错误的详细信息。将错误报告添加到您打开 PHP 标记之后的文件顶部,例如
<?php error_reporting(E_ALL); ini_set('display_errors', 1);然后是您的其余代码,以查看它是否产生任何结果。您想通过这一行实现什么$pic=($_FILES[' ']['name']);