[英]What is wrong in this PHP code, with SQL query?
许多天以前,我已经读过这个问题 。 然后,我尝试使用以下代码:
$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_id | my_str |
+--------+-----------------+
| id_1 | base64_str_1 |
| id_2 | base64_str_2 |
| id_3 | base64_str_3 |
| id_4 | base64_str_4 |
+--------+-----------------+
当我使用浏览器浏览PHP代码时,例如: http://localhost/my_php.php?code=id_3
。 它总是返回一个满足条件的文件(名为: id_3
)(其内容: base64_str_1
)。
您能否告诉我:“使用SQL查询,此PHP代码有什么问题?”。
使用此代码,您将从查询中获取最后一行ID的名称。 只是由于您将标头替换为:
header("content-disposition: inline; filename= " . $str_2['my_id'] . "");
内容是从所有str行串联而生成的。 因此,生成的内容是:
base64_str_1base64_str_2base64_str_3base64_str_4
不仅base64_str_1
如果需要从MyTable的一行中生成唯一文件,则可以使用:
$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'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.