2015-07-06 11:28
浏览 36


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()?

$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};";
        $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

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

        // Free the mysqli resources     

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.

<form action="test.php" method="get"/>
//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" />
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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.

    点赞 评论

相关推荐 更多相似问题