I'm trying to insert image information to a database, the url, name, type and size. I made my database like with thees names,
Idimage name size type url
The code that I have made will upload the image to a folder after that I was trying to get the information in the database, but it doesn't work.
The Codes:
<?php
if(isset($_POST['upload']))
{
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'root';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$name = $_FILES['file']['name'];
$type = $_FILES['file']['type'];
$size = $_FILES['file']['size'];
$sql = "INSERT INTO".
" `image`(`name`, `url`, `size`, `type`) VALUES " .
" (`$name`,".
"`images/contentImages/"."`$name`"."`$type`""".
",$size".
",`$type`)";
mysql_select_db('vgv');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully
";
mysql_close($conn);
}
?>
<?php include ('includes/header.php') ?>
<?php
use foundationphp\UploadFile;
$max = 1024 * 1024;
$result = array();
if (isset($_POST['upload'])) {
require_once 'src/foundationphp/UploadFile.php';
$destination = __DIR__ . '/images/contentImages/';
try {
$upload = new UploadFile($destination);
$upload->setMaxSize($max);
$upload->allowAllTypes();
$upload->upload();
$result = $upload->getMessages();
} catch (Exception $e) {
$result[] = $e->getMessage();
}
}
?>
<?php include ('includes/update_image.php'); ?>
<div id=box>
<div id="box-header">
</div>
<div id="box-container">
<div id="box-content">
</div>
<div id="box-footer"></div>
</div>
</div>
<div id="image-info">
<div id="image">
</div>
<div>
<table>
<tr>
<td class="benaming">Naam</td>
<td class="naam"></td>
</tr>
<tr>
<td class="benaming">Type</td>
<td class="naam"></td>
</tr>
<tr>
<td class="benaming">Afmeting</td>
<td class="naam"></td>
</tr>
<tr>
<td class="benaming">Grote(MB)</td>
<td class="naam"></td>
</tr>
<tr>
<td class="benaming">URL</td>
<td class="naam"></td>
</tr>
</table>
</div>
<div id="knoppen">
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="filename[]" id="filename" multiple>
<input type="submit" name="upload" id="submit" value="Upload File">
</form>
<?php
if ($result) {
foreach ($result as $message) {
echo '<script>alert($message);<script>';
}
}
?>
</div>
</div>
<?php include ('includes/footer.php') ?>
The problem was that it was not $_POST['sumbit'] but $_POST['upload']