PHP:我无法使用$ var内部的$ _POST更新我的数据库

时间:2018-02-16 16:02:08

标签: php post

我一直在尝试创建一个商店页面,每个商品都有一张图片。一切顺利,除非我上传图片,我想上传到我的数据库中的一些信息实际上不会被上传,我确信在做了一些研究,试验和错误之后我对这个问题有了新的错误。我应该问一下!

在这一行:

$qry = "INSERT INTO table_img (itemID, ext) VALUES 
('$_POST[$id]','$_POST[$fileActualExt]')";

$ id和$ fileActualExt的值不会在数据库中更新。我不能为我的生活找出原因,但我需要这两个才能正确显示我上传的任何图像。提前谢谢!

<?php

//This is from another table, used to link the two IDs together so the picture //and item will always be using the same ID. Right now I rely on auto_increment //due to my updating my table not working.
$id = $row['item_ID'];


if (isset($_POST['submit'])) {
    $file = $_FILES['file'];

    $fileName = $file['name'];
    $fileTmpName = $file['tmp_name'];
    $fileSize = $file['size'];
    $fileError = $file['error'];
    $fileType = $file['type'];

    $fileExt = explode('.', $fileName);
    $fileActualExt = strtolower(end($fileExt));

    $allowed = array('jpg', 'jpeg', 'png');

    if (in_array($fileActualExt, $allowed)) {
        if ($fileError === 0) { 
            if ($fileSize < 10000000) {
                echo "File successfully uploaded";

                $fileNameNew = "img".$id.".".$fileActualExt;
                $fileDestination = 'uploads/'.$fileNameNew;

                move_uploaded_file($fileTmpName, $fileDestination);


                $qry = "INSERT INTO table_img (itemID, ext) VALUES ('$_POST[$id]','$_POST[$fileActualExt]')";

                mysql_query($qry);

                echo "     $id, abc $fileActualExt";



            } else {
                echo "Your file is too big.";
            }

        } else {
            echo "There was an error uploading your file.";
        }

    } else {
        echo "You cannot upload files of this type. Please use JPG, JPEG or PNG.";
    }
}?>

0 个答案:

没有答案