1

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

  • Notice: Undefined index: photo in /Users/fatih/Sites/phpform/neu/adresse-bearbeiten.php on line 11
  • Notice: Undefined index: photo in /Users/fatih/Sites/phpform/neu/adresse-bearbeiten.php on line 18
  • Notice: Undefined index: photo in /Users/fatih/Sites/phpform/neu/adresse-bearbeiten.php on line 23
  • Sorry, there was a problem uploading your file.

Would be happy if someone can tell me what am i doing wrong? Regards

2 Answers 2

3

I would check the following things:

  1. Is your form's enctype set to multipart/form-data? It should be. (<form enctype="multipart/form-data">)

  2. 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.

Sign up to request clarification or add additional context in comments.

3 Comments

his form is not multipart/form-data
Oh, I didn't see that HTML at the bottom there. Yes, kara, I can't guarantee that your code will work WITH the proper enctype, but I can guarantee that it won't work WITHOUT it.
Jason thanks i got it solved. Could not see the missing part of multipart/form-data. I have added it to the form an all has been solved.. Thanks a lot
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.