Reputation: 39
Trying since some days to clear my Error with uploading an Image to a Folder and link to MySQL. I posted already my Problem but changed some codes thats why i want to post it again. Sorry if i spam.
This is my Code "adresse-bearbeiten.php"
<?php
require_once ('konfiguration.php');
$target = "images/";
$target = $target . basename( $_FILES['photo']['name']);
function sanitize( $input ){
return mysql_real_escape_string( htmlspecialchars( stripslashes( trim( $input ) ) ) );
}
if(isset($_POST['title']))
{
$title = sanitize($_POST['title']);
$description = sanitize($_POST['description']);
$applepart = sanitize($_POST['applepart']);
$partnumber = sanitize($_POST['partnumber']);
$productcode = sanitize($_POST['productcode']);
$compatibility = sanitize($_POST['compatibility']);
$image = sanitize($_FILES['photo']['name']);
$price = sanitize($_POST['price']);
$insert = mysql_query("INSERT INTO `adressbuch` (`title`,`description`,`applepart`,`partnumber`,`productcode`,`compatibility`,`photo`,`price`) VALUES ('$title','$description','$applepart','$partnumber','$productcode','$compatibility','$image','$price')");
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['photo']['name']). " has been uploaded, and your information has been added to the directory";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
if (!$insert)
{
die('Not saved: ' . mysql_error());
}
}
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<span>Neuer Eintrag:</span> <br />
<span>Title</span><input type="text" name="title" /> <br />
<span>Description</span><textarea cols="16" rows="5" name="description"></textarea> <br />
<span>Apple Part</span><input type="text" name="applepart" /> <br />
<span>Part Number</span><input type="text" name="partnumber" /> <br />
<span>Product Code</span><input type="text" name="productcode" /> <br />
<span>Compatibility</span><input type="text" name="compatibility" /> <br />
<span>Image</span><input type="file" name="photo" /> <br />
<span>Price</span><input type="text" name="price" /> <br />
<input type="submit" value="Speichern"/> <br />
</form>
The MySQL
CREATE TABLE IF NOT EXISTS `adressbuch` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`title` text,
`description` text,
`applepart` text,
`partnumber` text,
`productcode` text,
`compatibility` text,
`photo` text,
`price` text,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=26 ;
The Errors i get is listed below
Would be happy if someone can tell me what am i doing wrong? Regards
Upvotes: 1
Views: 2126
Reputation: 5981
Have you checked apache error log? Do you have permissions on target folder?
I've been working with a similar system in the company I work, and the common errors I had were:
1) Permissions on target folder 1.1) www-data must have permissions on target folder (If you run Linux) 2) Apache configuration in site definition (sites-enabled folder) where you set some directives, for example root_dir. This way Apache can restrict access to folders that aren't inside root_dir. (example /var/www).
Make a print_r($_FILES);
Do a check with isset to see if there is anything coming, else put something.
Example:
$T3 = isset($_POST['T3']) ? $_POST['T3'] : NULL;
Have you checked PHP reference for the error? photo is unset, which means this value isn't coming and you are trying to use it.
Upvotes: 0
Reputation: 45174
I would check the following things:
Is your form's enctype
set to multipart/form-data
? It should be. (<form enctype="multipart/form-data">
)
What happens when you do an echo '<pre>';print_r($_FILES);exit;
somewhere in your code? Does it output some info about your uploaded files? It should.
Upvotes: 3