-2

テーブルに情報を挿入するMySQLステートメントを書き込もうとしています。

 $insert = "INSERT INTO `vle`.`files`
               (`id`, `time`, `fileLocation`, `title`, `user`)

               VALUES (
                   NULL,
                   UNIX_TIMESTAMP(),

                   '".mysql_real_escape_string($putFile)."',
                   '".mysql_real_escape_string($_POST['title'])."',
                   '".$user."'
               )";

$userエコーアウトするが挿入されない変数を除いて、すべてが正しく挿入されます。同じことが。にも当てはまり$putFileます。このMySQLステートメントに私が間違っていることはありますか?

ありがとう

ここに完全なコード

    <?php require_once('Connections/localhost.php');
    include('pageCheck.php');
    include('adminCheck.php');

    function saveFile(){
        global $_FILES, $_POST;

        $insert = "INSERT INTO `vle`.`files` 
(`id`, `time`, `fileLocation`, `title`, `user`) 
VALUES (NULL, UNIX_TIMESTAMP(), '".mysql_real_escape_string($putFile)."', '".mysql_real_escape_string($_POST['title'])."', '".$user."')";

        mysql_query($insert);

        var_dump($insert);
    }

    $putFile = "files/".basename($_FILES['uploadedFile']['name']);

    if(move_uploaded_file($_FILES['uploadedFile']['tmp_name'], $putFile)){
        saveFile();
        echo"File has been uploaded, Redirecting to file list now...";
        //echo"<meta http-equiv='refresh' content='3;url=dashboard.php'>";

        }else{

        echo"Unable to upload file, Returning to dashboard...";
        //echo"<meta http-equiv='refresh' content='3;url=dashboard.php'>";  

        }


     ?>

$userusはpageCheck.phpで定義されています

4

1 に答える 1

3

あなたの問題はスコーピングの問題です。saveFile()関数内で$userあり$putFile、範囲内ではありません。

http://php.net/manual/en/language.variables.scope.phpを参照してください

それらを引数として渡すことを検討する必要があります。

function saveFile($user, $file, $title) {
    // etc
}

saveFile($user, $putFile, $_POST['title']);
于 2012-04-18T03:55:40.427 に答える