【发布时间】:2011-03-03 19:56:26
【问题描述】:
我有以下代码:
代码1:
<div name="content">
<a id="various3" href="picture.php" title="<?php echo $info; ?> " idno="5" >
<img class="last" src="./images/page11.png" />
</a>
</div>
代码2:
<script language="javascript" type="text/javascript">
$(document).ready(function() {
var imagelinks = $('div[name=content] a');
idno = imagelinks.attr('idno');
document.getElementById("pid").value = idno;
</script>
代码3:
<form id="target" method="get" action="picture.php?=">
<input id="pid" name="pid" value="" />
代码4:
<?php
$host = 'localhost';
$user = 'root';
$pw = '';
$db = 'thepillar';
$phpVar = $_GET["pid"];
mysql_connect($host,$user,$pw);
mysql_select_db($db);
$sql = "select pics, ext from infopics where id='$phpVar'";
$result = mysql_query($sql) or die('Bad query at 12!'.mysql_error());
while($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
$db_img = $row['pics'];
$type = $row['ext'];
}
$img = base64_decode($db_img); //print_r($db_img );
$img = imagecreatefromstring($img);
header("Content-Type: image/jpeg");
imagejpeg($img);
imagedestroy($img);
?>
.code1、code2、code3在同一个页面index.php,code4在另一个页面picture.php。
我想要的流程是,当 index.php 加载 code2 时,将内部的每个标记分配为 imagelinks,然后声明一个 javascript 变量 idno,然后将 code1 中我的标记中的 idno 属性设置为其值。
idno = imagelinks.attr('idno');
接下来
document.getElementById("pid").value = idno;
此代码将 javascript 变量 idno 设置为我的 code3 中输入 id="pid" 的值。结果,我的 index.php 上出现了一个文本框,其中包含我的 code3 中的值。
。我要做的是将pid值传递给我的picture.php中的code4并将其存储为$phpVar的值
$phpVar = $_GET["pid"];
当我点击 code1 中的标签而不是使用 .
【问题讨论】:
-
这篇文章是stackoverflow.com/questions/5160247/… 的延续吗?为什么不编辑第一个,因为它没有解决?
-
另外,向 html 元素添加不存在的属性 (idno) 在很多浏览器中都不起作用,您不应该这样做。
-
你有一个 SQL 注入漏洞。切勿在 SQL 查询中使用用户可以更改的变量(例如 $_GET)。请改用 PDO,或者如果您不能使用它,请至少在您的
$sql上使用mysql_real_escape_string(),然后再使用mysql_query()。 -
@VirtualBlackFox - 是的。我很抱歉。我现在很困惑,因为这个项目是为了我的论文。 T_T
-
.@itchy - 我使用了 mysql_real_escape_string() 但仍然没有任何变化。
标签: php javascript jquery html