2015-01-21 53 views
0

我正尝试构建一个文件上传器,其中包含一个不包含文件的YouTube教程,现在我被卡在了名称上。使用$ _Files不会返回任何结果,我不确定原因。 :/

我试图回应它,但没有回来。

尽管一切似乎工作。

<html> 
<head> 
</head> 
<body> 
<?php 

error_reporting(-1); 
ini_set('display_errors', 'On'); 

$con = mysql_connect("localhost","root","root"); 
if (!$con){ 
die("Can not connect: " . mysql_error()); 
} 
mysql_select_db("example",$con); 

if(isset($_POST['update'])){ 
$UpdateQuery = "UPDATE repo SET location='$_POST[location]', name='$_POST[name]', description='$_POST[description]' WHERE location='$_POST[hidden]'";    
mysql_query($UpdateQuery, $con); 
}; 

if(isset($_POST['delete'])){ 
$DeleteQuery = "DELETE FROM repo WHERE location='$_POST[hidden]'";   
mysql_query($DeleteQuery, $con); 
}; 

if(isset($_POST['add'])){ 

$AddQuery = "INSERT INTO repo (name, id, image, location, partners, description, date) VALUES ('$image_name', '','$_POST[uimage]', '$_POST[ulocation]', '$_POST[upartners]', '$_POST[udescription]', NOW())";   
mysql_query($AddQuery, $con); 
}; 



$sql = "SELECT * FROM repo"; 
$myData = mysql_query($sql,$con); 
echo "<table border=1> 
<tr> 
<th>Image</th> 
<th>Name</th> 
<th>Location</th> 
<th>Partners</th> 
<th>Description</th> 
<th>Date</th> 
</tr>"; 
while($record = mysql_fetch_array($myData)){ 
    ?> 
<form action="mydata5.php" 
method="post" enctype="multipart/form-data"> 

<?php 
echo "<tr>"; 

echo "<td>" . "<img src=Assets/Images/" . $record['name'] . " </td>"; 

echo "<td>" . "<input type=text name=topic value=" . $record['name'] . " </td>"; 

echo "<td>" . "<input type=text name=name value=" . $record['location'] . " </td>"; 

echo "<td>" . "<input type=text name=name value=" . $record['partners'] . " </td>"; 

echo "<td>" . "<input type=text name=description value=" . $record['description'] . " </td>"; 

echo "<td>" . "<input type=text name=description value=" . $record['date'] . " </td>"; 

echo "<td>" . "<input type=hidden name=hidden value=" . $record['location'] . " </td>"; 

echo "<td>" . "<input type=submit name=update value=update" . " </td>"; 
echo "<td>" . "<input type=submit name=delete value=delete" . " </td>"; 
echo "</tr>"; 
echo "</form>"; 
} 
echo "<form action=mydata5.php method=post>"; 
echo "<tr>"; 

// echo "<td><input type=file name=uimage></td>"; 

?> 

<td><input type="file" name="uimage" id="uimage"></td> 

<?php 
$file = $_FILES['uimage']['tmp_name']; 
$image_name = mysql_real_escape_string($_FILES['uimage']['name']); 
echo $_FILES['uimage']['error']; 

echo "<td><input type=hidden name=uname></td>"; 
echo "<td><input type=text name=ulocation></td>"; 
echo "<td><input type=text name=upartners></td>"; 
echo "<td><input type=text name=udescription></td>"; 

echo "<td>" . "<input type=submit name=add value=add" . " </td>"; 
echo "</form>"; 
echo "</table>"; 
mysql_close($con); 

?> 

</body> 
</html> 
+0

在表单标签中加入这个,enctype =“multipart/form-data” – 2015-01-21 07:57:43

回答

2

您需要在表单标签中添加enctype="multipart/form-data"

2

对于文件类型字段,你需要添加enctype属性的表单以便上传的文件可以用$ _FILES

更新的形式开始标记下面

<form action="mydata5.php" 
method="post" enctype="multipart/form-data"> 
+0

嘿,感谢您的快速帮助。我添加了它并编辑了我的帖子。我似乎还没有做任何事情。我是否使用我的名字/编号错误? – Ozymandias 2015-01-21 08:06:08

+0

是的,当我这样做时,您需要将字段名称打包为引号 – Nick 2015-01-21 08:11:32

+0

。 :/ – Ozymandias 2015-01-21 08:14:17

0

支票访问您插入Query.You正在使用$ _POST作为图像名称。那是错的。

+0

的表单中添加此表单属性是什么? 0_0不,我不是。 (''image_name','','$ _ POST [uimage]','$ _POST [ulocation]', '$ _POST [upartners]','$ _POST [udescription]',NOW())“; mysql_query($ AddQuery,$ con); – Ozymandias 2015-01-21 08:02:43