douzhan4522 2015-07-06 11:28
浏览 38
已采纳

在数据库中定义数组

I downloaded a zip file from a database but am unable to find what I should put in the $file_names = array()? When I run the file the error displayed is No ID Selected

I think that this is because there is nothing inside the array(). Can someone help me define the array()?

<?php
$file_names = array();
// Make sure an id was passed
if (isset($_GET['id'])) {
    // Get the id into string (in case of an array)
    $id_pass = implode(",",$_GET['id']);
    // Make sure the name is in fact a valid
    if ($id_pass <= 0) {
        die ('No ID Selected!');
    } else {
        // codes to connect to the database is here

        // Fetch the file information
        $query = "select * from docu  where id = {$id_pass};";
var_dump($result);
        $result = $dbLink->query($query);

        if ($result) {
            // Make sure the result is valid
            if ($result->num_rows == 1) {
                // Get the row
                $row = mysqli_fetch_assoc($result);

                //zip function

                $zip = new ZipArchive();
                $filename = "export_" . date('Y.m.d H.i.s') . ".zip";

                if ($zip->open($filename, ZIPARCHIVE::CREATE |   ZIPARCHIVE::OVERWRITE) !== true) {
                    echo "Cannot Open for writing";
                }


                $ext = $row['name'] . ".pdf"; // taking file name from DB and adding extension separately
                $zip->addFromString($ext, $row['content']); //adding blob data from DB
                $zip->close();

                header("Content-disposition: inline; filename='.$filename'");
                header('Content-type: application/zip');
                readfile($filename);
                unlink($filename);
            }
        }

        // Free the mysqli resources     
        mysqli_free_result($result);
        mysqli_close($dbLink);
    }
}

result of var_dump($result):

object(mysqli_result)#2 (5) { ["current_field"]=> int(0) ["field_count"]=> int(2) ["lengths"]=> NULL ["num_rows"]=> int(22) ["type"]=> int(0) }

Here is the HTML Form.

<html>
<form action="test.php" method="get"/>
<?php
//codes to connect to the database is here
 mysqli_select_db($con, "images");
 $query = "SELECT id, name FROM docu  order by id";
 $result = mysqli_query($con, $query) or die('Error, query failed');

if (mysqli_num_rows($result) == 0) {
    echo "Database is empty <br>";
} else {
    while ((list($id, $name) = mysqli_fetch_array($result, MYSQLI_BOTH))) {
        echo "<input type='checkbox' name='id[]'>";
        echo $name . " " . $id . " " . "<br>"; //id and name removed
    }
}
?>
   <input type="submit" name="submit" value="Submit" />
</html>
  • 写回答

1条回答 默认 最新

  • dongshen7407 2015-07-06 15:33
    关注

    Do this. In your while loop:

    echo "<input type='checkbox' name='$id' value='$id'>";
    

    and it should work.

    Explanation: When you post a form on your server, the checkbox's value is taken by the value contained in it. Since you were not putting anything in your value, you were not able to get the id on your server.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向