I have the code to upload an image to the server, but the PHP code for saving the image path to the database has a problem.It does not update the database. It shows the following errors and con not udate the database:
( ! ) Notice: Undefined index: fileToUpload in C:\wamp\www\hosty\Uploads.php on line 4
( ! ) Notice: Undefined index: datereg in C:\wamp\www\hosty\Uploads.php on line 8
( ! ) Notice: Undefined index: Description in C:\wamp\www\hosty\Uploads.php on line 9
( ! ) Notice: Undefined index: title in C:\wamp\www\hosty\Uploads.php on line 10
( ! ) Notice: Undefined index: fileToUpload in C:\wamp\www\hosty\Uploads.php on line 26
<?php require_once('Connections/Conn_host.php'); ?>
<?php
error_reporting(0);
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$datereg=$_POST['datereg'];
$Description=$_POST['Description'];
$title=$_POST['title'];
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}}
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
mysql_select_db($database_Conn_host, $Conn_host);
$query_rsUpload = "insert into infor(title,Description,userId,datereg,name,path) values('$title','$Description',,'','$datereg','$name','uploads/$name')";
$rsUpload = mysql_query($query_rsUpload, $Conn_host) or die(mysql_error());
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
<!DOCTYPE html>
<html>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
<p>
<label>Title
<input name="title" type="text" id="title" />
</label>
</p>
<p>
<label for="Description">Description</label>
<textarea name="Description" id="Description" cols="45" rows="5"> </textarea>
</p>
<p>
<input name="userId" type="hidden" id="hiddenField" />
<input name="datereg" type="hidden" id="hiddenField2" />
</p>
<p>Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</p>
</form>
</body>
</html>