duanjiu1950 2015-09-03 15:06
浏览 15
已采纳

这个PHP代码有什么问题,有SQL查询吗?

Many days ago, I have read this question. Then, I have tried with this code:

$code = $_GET['code'];
$str_1 = mysql_query("SELECT * FROM `MyTable`");
while ($str_2 = mysql_fetch_array($str_1)) {
    header("content-type: application/octet-stream");
    header("content-disposition: inline; filename= " . $str_2['my_id'] . "");
    echo base64_decode($str_2['my_str']);
}

My my data base, there are some data:

+--------+-----------------+
|  my_id |     my_str      |
+--------+-----------------+
|  id_1  |  base64_str_1   |
|  id_2  |  base64_str_2   |
|  id_3  |  base64_str_3   |
|  id_4  |  base64_str_4   |
+--------+-----------------+

When I browse my PHP code with browser, such as: http://localhost/my_php.php?code=id_3. It always returns a file (named: id_3) which is contented (it's content: base64_str_1).

Can you tell me: "What is wrong in this PHP code, with SQL query?".

  • 写回答

1条回答 默认 最新

  • douqianke7467 2015-09-03 15:51
    关注

    With this code, You'll get the name of last row id from query. Just due to you replaced the header in:

    header("content-disposition: inline; filename= " . $str_2['my_id'] . "");
    

    The content, is being generated with a concatenation from all str rows. So, the generated content is:
    base64_str_1base64_str_2base64_str_3base64_str_4 and not only base64_str_1

    If you need to generate a unique file from one row from MyTable, you could to use:

    $code = $_GET['code'];
    $str_1 = mysql_query("SELECT * FROM `MyTable` where my_id = '$code'");
    header("content-type: application/octet-stream");
    header("content-disposition: inline; filename= " . mysql_result($str_1, 0, 'my_id') );
    echo base64_decode(mysql_result($str_1, 0, 'my_str'));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line