我在代碼中提到「錯誤行」表示行顯示此錯誤「注意:未定義的索引:C:\ xampp \ htdocs \ Lab \ register2.php中的文件在行33」 。但在我的數據庫中增加的數據意味着主鍵(id)。我需要在PHP中解決它請幫助我。文件上傳未定義索引錯誤php
<?php
if(isset($_POST['btn_upload']))
{
$fullname=$_POST["fullname"];
$file = rand(1000,100000)."-".$_FILES['file']['name']; //Error line
$file_loc = $_FILES['file']['tmp_name']; //Error line
$info = pathinfo($_FILES['file']['name']); //Error line
$ext = $info['extension']; //Error line
$newname = $userid.".".$ext; //Error line
$target = 'uploads/'.$newname;
move_uploaded_file($_FILES['file']['tmp_name'], $target); //Error line
require_once "config.php";
$db=get_connection();
$sql="INSERT INTO user(Path) VALUES('$newname')";
mysql_query($sql);
}
?>
<!DOCTYPE html>
<html>
<title></title>
<body>
<center>
<form action="#" method ="POST">
Full Name : <input type="text" name="fullname"/><br/>
Phone : <input type="number" name="phone"/><br/>
Address :<textarea rows="4" cols="30" name="textin"></textarea><br>
Profile Picture : <input type="file" name="file" /> <button type="submit" name="btn_upload">Upload Image</button><br/>
<input type= "submit" name ="back" value="Back"/><br/>
<input type= "submit" name ="next1" value="Next"/>
</form>
</center>
</body>
</html>
嘗試在您的表單元素中添加'enctype =「multipart/form-data」'。 http://stackoverflow.com/questions/4526273/what-does-enctype-multipart-form-data-mean – chris85
你剛剛更新了你的問題,而不是在這裏問以前的評論?如果表單沒有提交文件,索引不會存在。或者我想你可以做一個空/ isset檢查似乎毫無意義,雖然當你可以解決問題時......你也可以關閉錯誤報告或抑制錯誤(我不會採取的路線)。 – chris85