-2

This code of mine is to upload videos and same it in the database .I am getting only 1 notice that is "Undefined index: video "

Notice: Undefined index: video in C:\wamp\www\SSP Final project\php\upload.php on line 5

Notice: Undefined index: video in C:\wamp\www\SSP Final project\php\upload.php on line 13

Notice: Undefined index: text in C:\wamp\www\SSP Final project\php\upload.php on line 14

Notice: Undefined index: video in C:\wamp\www\SSP Final project\php\upload.php on line 20

hear is the form

<form method="POST" action="../../php/upload.php" enctype='multipart/form-data'>
                <table class="booking_table"  cellpadding="40" style="margin:auto;margin-top:10px;">
                    <tr>
                        <td>
                            <input type="hidden" name="size" value="90000000000">
                            <input type="file" name="video">
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <textarea name="text" cols="40" rows="4" placeholder="Say something about Yout band......"></textarea>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <input type="submit" name="upload" value="Upload ">
                        </td>
                    </tr>
                </table>
            </form> 

and hear is the php

var_dump($_FILES);

//the parth to store the upload video
$target= "../videos/".basename($_FILES['video']['name']);

//conect to database
$db = mysqli_connect('localhost', 'root', '', 'sspfinal');



//get all the submited data from the form
$image = $_FILES['video']['name'];
$txt = $_POST['text'];

$sql="INSERT INTO band(video,text) values ('$image','$txt')";
mysqli_query($db,$sql);//store the submited data into the database table : bands

//move the upload image to the folder
if(move_uploaded_file($_FILES['video']['name'].$target)){
    $msg="Image Uploaded Successfully";
}
else{
    $msg="There was a problem to upload";
}

help me to find this fault

  • @PaulCrovella Even though I agree that the question "should" be closed with the "possible" duplicate; that Q&A should be updated to include an answer for "files", since it doesn't contain one ("community wiki") or more about `$_FILES` and the valid enctype required for file handling. However, there are other duplicates about "just" the missing enctype, I'd just need to go find one. – Funk Forty Niner Apr 01 '17 at 03:15
  • @PaulCrovella Addendum to my above; I closed the question and used the one about files to be first on the list and the one you marked as under it. If at all possible and when it's about files (in the future), can you choose the duplicate "for" files please? Many may not know what to do with just the one. We have to remember to put ourselves in their shoes; we have all been "there" ;-) – Funk Forty Niner Apr 01 '17 at 03:21
  • **WARNING**: When using `mysqli` you should be using [parameterized queries](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and [`bind_param`](http://php.net/manual/en/mysqli-stmt.bind-param.php) to add user data to your query. **DO NOT** use string interpolation or concatenation to accomplish this because you have created a severe [SQL injection bug](http://bobby-tables.com/). **NEVER** put `$_POST`, `$_GET` or **any** user data directly into a query, it can be very harmful if someone seeks to exploit your mistake. – tadman Apr 01 '17 at 03:29
  • Please don't use code given from an answer below and overwrite your original post (I rolled the question back). People visiting would have seen the enctype in your edit and the answer below and ask themselves: *"The enctype is there, why the answer?"* and in possibly in turn downvoting it. The person who gave the answer should have responded to the (deleted) comment you left under it. If they were not able to respond, then they may no longer be logged in. You'll just have to wait. The duplicates that the question was closed with, contain enough information for you to fix this. – Funk Forty Niner Apr 01 '17 at 03:47

1 Answers1

0

You forgot to use enctype='multipart/form-data' in the form tag to send the file.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Niklesh Raut
  • 34,013
  • 16
  • 75
  • 109