0
<?php
include "session.php";
$con=mysqli_connect("localhost","root","","project");
if (isset($_POST['submit'])) {
    $a=$_POST['title'];
    $b=$_POST['catagory'];
    $c=$_POST['textarea'];
    $g=$_FILES['upload']['name'];
    $tmp_name = $_FILES['upload']['tmp_name'];
    $d=$_POST['country'];
    $e=$_POST['city'];
    $f=$_POST['mobilenumber'];

    if (isset ($g)) {
        if (!empty($g)) {
            $location = 'uploads/';
            if  (move_uploaded_file($tmp_name, $location.$g)){
                $query = "insert into productadd(title,catagory,textarea,upload,country,city,mobilenumber) VALUES ('$a','$b','$c','$g','$d','$e','$f')";
                $result = mysqli_query($con, $query);
                if($result){
                    $smsg = "Successfully Submitted";
                }else{
                    $fmsg ="Fail";
                }
            }
        }
    }
}
mysqli_close($con);
?>

<form action="" method="post" enctype="multipart/form-data">
  <div>
    <input type = "text" id = "title" name = "title" required placeholder=" " />
    <label for ="title"> Title</label> 
  </div>
  
  <div>
  <select name="category" id="select">
   <option>--Select Category--</option>
   <option>Website</option>
   <option>Android App</option>
   <option>IOS App</option>
   <option>Other</option>
   </select>
    <label for = "email"> Category</label>
    <div class="requirements">
     Please Enter category.
</div>
</div>

<div>
  <textarea id="textarea" name="textarea" cols="25" rows="7"></textarea> 
  <label for ="textarea"> Descriptions</label> 
</div>

<div>
    <input type="file" id="upload" name="upload" placeholder=" " />
    <input type="txt" id="name" name="name"  placeholder=" " />
</div>

<div>
   <select id="country"name="country">
     <option value="">Country...</option>
     <option value="Afghanistan">Afghanistan</option>
     <option value="Albania">Albania</option>
     <option value="Algeria">Algeria</option>
     <option value="American Samoa">Other</option>
  </select>
    <label for = "country">Country</label>
</div>

<div>
    <input type="text" id="city" name="city" required placeholder=" " />
    <label for="city">City</label>
</div>

<div>
    <input type="text" id="mobilenumber" name="mobilenumber" required placeholder=" " />
    <label for="mobilenumber">Mobile #</label>
</div>
<div>
  <center>
</div>
  <center>
    <input type="submit" id="submit" name="submit" value="Submit" /> 
  </center>
</form>

I am unable to upload images on MySQL DB.

Code giving undefined index "upload" error at 9 ,10 lines. But if I use if(isset($_FILES['upload']), then this error is not showing up but image is not uploaded in database.

Please if anyone know how to solve this problem please give your opinion.

Moinuddin Quadri
  • 46,825
  • 13
  • 96
  • 126
dasdsadsa
  • 1
  • 1
  • Possible duplicate of [PHP: "Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-notice-undefined-index-and-notice-undef) – M. Eriksson Jan 23 '17 at 06:29
  • 3
    may be error is not here. show your post Form or show your HTML coding where you upload your image – krishn Patel Jan 23 '17 at 06:31
  • form code have some naming problem. show us. is you have html like this:-`` also `enctype="multipart/form-data"` needed into form – Alive to die - Anant Jan 23 '17 at 06:31
  • plz check , have u added enctype="multipart/form-data" in form – Vikas Umrao Jan 23 '17 at 06:33
  • your form tag must have enctype. have you checked. – Jyoti mishra Jan 23 '17 at 06:34
  • yes enctype="multipart/form-data" already placed in form, but not working :/ – dasdsadsa Jan 23 '17 at 06:37
  • You are wide open to [SQL Injections](http://php.net/manual/en/security.database.sql-injection.php) and should really use [Prepared Statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) instead of concatenating your queries. – M. Eriksson Jan 23 '17 at 06:39
  • In your form, the action attribute is emtpy. Is your PHP-code on the same page as your form? Or are you posting the form using javascript/ajax? – M. Eriksson Jan 23 '17 at 06:41
  • thanks everyone, I restated xampp and problem solved dont know how, but solved without any change in code – dasdsadsa Jan 23 '17 at 06:52
  • Categorically, there's only one a in category – Strawberry Jan 23 '17 at 08:19

1 Answers1

0

May be try this "In your "php.ini" file, search for the file_uploads directive, and set it to On:

file_uploads = On "

http://www.w3schools.com/php/php_file_upload.asp

boyshot17
  • 39
  • 3