0

I am trying to build a file uploader, with a youtube tutorial that doesn't cover files, and right now I am stuck on the name. Using $_Files returns nothing and I am unsure as to why. :/

I tried to echo it out, but nothing comes back.

Everything else seems to work though.

<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>
Ozymandias
  • 199
  • 6
  • 17

3 Answers3

2

You need to add enctype="multipart/form-data" in the form tag.

Gaurav
  • 28,447
  • 8
  • 50
  • 80
2

For file type fields you need to add enctype attribute in your form so that uploaded files can be access using $_FILES

Update form starting tag with below

<form action="mydata5.php"
method="post" enctype="multipart/form-data">
Bhavya Shaktawat
  • 2,504
  • 1
  • 13
  • 11
0

Check your Insert Query.You are using $_POST for image name. That is wrong.

Sunil Pachlangia
  • 2,033
  • 2
  • 15
  • 25
  • what? 0_0 no I am not. $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); – Ozymandias Jan 21 '15 at 08:02