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.

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度