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 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值