【问题标题】:Form within iframe doesn't run properlyiframe 中的表单无法正常运行
【发布时间】:2015-11-10 05:30:12
【问题描述】:

我正在尝试在 iframe 中执行一个简单的“获取”表单,如下所示:

<iframe width = 60% height= 100% id="dynamic-content" src="imageViewing.php" />

这是imageViewing.php:

<html>
<meta http-equiv="refresh" content="8">
<?php
//*database conncetion settings*
$query = "SELECT team_name,id,content FROM upload WHERE display='1'";
$result = mysql_query($query) or die('Error, query failed'.mysql_error());
while ($row = mysql_fetch_assoc($result))
{
	$id = $row['id'];
	echo $row['id']. '<img width="200" height = "200" src="data:image/png;base64,' . base64_encode($row['content']) . ' " />'. $row['team_name']."<form method='get' action='imgApproved.php?id='$id'><input type='submit' value='Approve'/></form><br>";
}
exit;
mysql_close();
?>
</html>

单击按钮运行 imgApprove.php,它会更改特定图像的“显示”参数,以便下次 iframe 刷新时不会显示。

<?php
if (isset($_GET['id']))
{
	$id = $_GET['id'];
	//*Connect to database stuff*
	$query = "UPDATE upload SET display='0' WHERE id='$id'";
	$result = mysql_query($query) or die('Error, query failed'.mysql_error());
	header("location:imageViewing.php");
}
?>

但是,当我点击批准时,iframe 停止刷新并且不再显示任何内容。但是,如果我刷新页面,仍然会显示所有图像(所以我假设 imgApprove.php 没有更改 display 的值)。我在这里遗漏了一些简单的东西吗?

编辑我一直在做一些进一步的测试,结果是:if (isset($_GET['id'])) 正在返回 false,甚至没有运行代码,所以问题一定出在 $id 变量的传递上.

【问题讨论】:

  • 首先,您应该避免使用 mysql_* 函数,因为它已被弃用并标记为删除。考虑使用 Mysqli,或者更好的是 PHP 数据对象 (PDO)。您的代码呈现方式容易受到 SQL 注入攻击。
  • 我正在使用支持 PHP5.3 且没有更新的网络托管站点。我的代码以何种方式易受攻击(我还不完全了解 sql 安全性)
  • Mysqli 是在 5.3.0 版本中实现的。在这里阅读:stackoverflow.com/questions/60174/…
  • 另外,您的代码有点混乱。单击“批准”后,会发生什么?您正在从给定 ID 参数的“上传”表中获取“显示”值,将其存储在数组 $row 中并将其 display 字段值更改为 0,然后将页面重定向回上一页。你想发生什么?
  • 点击“批准”-> imgApprove.php 应该运行并更改当前图像上的“显示”(使用 id 查找)并返回上一页。我现在看到了问题所在 - 而不是更改表中“显示”的实际值,我只是在本地分配一些东西给 $row['display']

标签: php html forms iframe


【解决方案1】:

我认为问题是由未关闭的 iframe 引起的。我需要在&lt;iframe&gt; 声明之后添加&lt;/iframe&gt;。两者之间的任何内容都是 iframe 加载失败时显示的文本。

【讨论】:

    猜你喜欢
    • 2018-07-05
    • 1970-01-01
    • 2018-08-26
    • 1970-01-01
    • 2014-07-01
    • 1970-01-01
    • 2021-04-22
    • 2015-12-08
    • 2019-02-08
    相关资源
    最近更新 更多