I am trying to create a code that will be able to upload and store an image to a database so I can then retrieve them on another page.
After watching a video on how to upload and stroe an image to a database I come up with an error indicating an Undefined variable: imageName, although I have initiated it and use it all over the code
Undefined variable: imageName
<?php
$pagetitle="Image Management";
session_start();
include_once('head.php');
include_once('stylesheets.php');
?>
</head>
<?php
include_once('navbar.php');
connectDB();
?>
<body>
<div class="container">
<form action ="NImageManagement.php" method="post" enctype="multipart/form-data">
<input type="file" name="image"><input type="submit" value="Upload">
</form>
<?php
if(isset($_POST['submit']))
$imageName = mysql_real_escape_string($_FILES["image"]["name"]);
$imageData = mysql_real_escape_string(file_get_contents($_FILES["image"]["tmp_name"]));
$imageType = mysql_real_escape_string($_FILES["image"]["type"]);
if(substr($imageType,0,5) =="image")
{
mysql_query("INSERT INTO 'blob' VALUES('', '$imageName', '$imageData')");
echo "Image Uploaded";
}else{
echo "Only images are allowed!";
}
?>
</div>
</body>
</html>
<?php
include_once('footer.php');
?>
I know that the code is not safe as it is but I plan to fix it after I have the main functions ready and working. Any assistance on my problem will be greatly appreciated