1

That's my code

<?php 
    mysqli_connect('localhost','root','','vuap');

    if(isset($_POST['submit'])){
        $name = $_FILES['file']['name'];
        $temp = $_FILES['file']['temp_name'];
        move_uploaded_file($temp,"uploaded/".$name);
        mysqli_query("INSERT INTO video ('movie') VALUE (''$name')" );

    }


    <form action="index.php" method="post" enctype="multipart/form-data">
        <input type="file" name="file" >
        <input type="submit" name="submit" value="gonder">
    </form>
    <?php 
    if(isset($_POST['submit'])){
        echo "<br>".$name."has been uploaded";
    };
    ?>

I can upload images but not videos, for some reason.

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
  • Whats the error? Check max upload limit, and max post size in php.ini. VALUE (''$name') , remove one quote there, '$name', dont forget to escape – Muhammed Mar 08 '16 at 15:48
  • 1
    first of all upper code must be down inside ` – Alive to die - Anant Mar 08 '16 at 15:49
  • This `mysqli_query("INSERT INTO video ('movie') VALUE (''$name')" );` is breaking your query for three reasons. IF... that's your real code. And no, it's not `VALUE`. It's to the left and right of it and what you didn't do, *execute the query*. Using http://php.net/manual/en/mysqli.error.php would have told you about the syntax errors. – Funk Forty Niner Mar 08 '16 at 15:53
  • Is this the exact code you're using? – Phiter Mar 08 '16 at 15:54
  • Using http://php.net/manual/en/function.error-reporting.php would tell you if that video file's too large also. Too many possible reasons for your code to fail and as I already outlined. Basic rule of thumb: check for errors. – Funk Forty Niner Mar 08 '16 at 15:57
  • I write sql BLOB and working. my php.ini max upload limit 300MB it no error . –  Mar 20 '16 at 20:09

1 Answers1

1

There's quite a few things wrong in your code.

This mysqli_query("INSERT INTO video ('movie') VALUE (''$name')" ); is breaking your query for three reasons.

  • Wrong identifier qualifiers
  • Extra quote for the VALUE
  • Not executing the query

IF... that's your real code.

And no, it's not VALUE, it's what's to the left and right of it and what you didn't do, execute the query.

Using error checking http://php.net/manual/en/mysqli.error.php on your query, would have told you about the syntax errors you made being using the identifier qualifiers for your table being regular quotes, rather than ticks or no quotes at all, and the additional quote in ''$name'.

Consult the following on identifier qualifiers in MySQL:

You also need to assign a variable to your connection and check for errors.

$connect = mysqli_connect('localhost','root','','vuap') 
            or die (mysqli_error($connect));

Then add that to your query:

$result = mysqli_query($connect, "INSERT INTO video (`movie`) VALUE ('$name')" );

then

if(!$result){

   echo "Error: " . mysqli_error($connect);

}

else {
   echo "Success!";
}

You also don't need this, just remove it:

if(isset($_POST['submit'])){
    echo "<br>".$name."has been uploaded";
};

and make sure that the folder you're wanting to upload to, has the proper permissions to write to it and that the video you're wanting to upload is within the maximum allowed size.

Consult: PHP change the maximum upload file size

Sidenote: For those who think that VALUE isn't valid, it is in MySQL.

Consult: http://dev.mysql.com/doc/refman/5.7/en/insert.html

Example:

INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
    [INTO] tbl_name
    [PARTITION (partition_name,...)] 
    [(col_name,...)]
    {VALUES | VALUE} ({expr | DEFAULT},...),(...),...
    [ ON DUPLICATE KEY UPDATE
      col_name=expr
        [, col_name=expr] ... ]

Footnotes:

Your present code is open to SQL injection. Use mysqli_* with prepared statements, or PDO with prepared statements.


Additional notes:

If you're wanting to upload the data as binary rather than a string, then you will need to use either BLOB or LONGBLOB and escape the data.

Otherwise, it will throw you an error.

I.e.:

$name = $_FILES['file']['name'];
$name = mysqli_real_escape_string($connect, $name);

Consult the manual on BLOB:


Add error reporting to the top of your file(s) which will help find errors.

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);

// Then the rest of your code

Sidenote: Displaying errors should only be done in staging, and never production.

Community
  • 1
  • 1
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141