我想调用在php区域顶部声明的Javascript函数。然而它不工作。谁能告诉我它的原因。除了这部分,其他所有部分都在工作。请帮帮我。用php代码调用javascript函数
<!doctype HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>AES (Rijndael) Encryption Test in JavaScript</title>
<script src="aes-enc.js" type="text/javascript" language="JavaScript"></script>
<script src="aes-dec.js" type="text/javascript" language="JavaScript"></script>
<script src="aes-test.js" type="text/javascript" language="JavaScript"></script>
<script type="text/javascript">
function doDecryption()
{
document.write("Inside Javascript");
var ct, key;
ct = hex2s(<?php echo $myValue; ?>);
document.write("Inside Javascript");
document.write(ct);
// key = hex2s(theForm.key.value);
// theForm.plaintext.value = byteArrayToHex(rijndaelDecrypt(ct, key, "ECB"));
}
</script>
</head>
<body>
<?php
mysql_connect("localhost","root","");
mysql_select_db("encryption") or die(mysql_error());
$userId = $_POST['userId'];
if (($_SERVER['REQUEST_METHOD'] == 'POST') && ($_POST['key'] == ""))
{
$query = mysql_query("select * from employee_details where id = '$userId'"); if($row=mysql_fetch_assoc($query))
{
echo '<tr>';
foreach($row as $value)
echo '<td>'.$value.'</td>';
echo '</tr>';
}
else { echo "No rows returned"; }}
else if (($_SERVER['REQUEST_METHOD'] == 'POST') && ($_POST['key']))
{
$columname = "ciphertext";
$tablename = "employee_details";
function getField($field, $tbl_name, $condition)
{
$result = mysql_query("SELECT $field FROM $tbl_name WHERE id = ".$condition);
return @mysql_result($result, 0);
}
$myValue = getField($columname,$tablename,$userId);
echo "$myValue";
[B]echo '<script type="text/javascript">
doDecryption();
</script>';[/B]
echo "whats happening";
//doDecryption();
}
?>
</body>
</html>
是什么,输出什么样子时,添加周围的引号? – jensgram 2010-12-02 09:04:39
我明白了为什么在我的脑海里运行代码后失败了。如果您提供了错误消息,解决起来会更容易。就此而言,作为一个经验法则,尝试将问题分解为“为什么JS不工作?”或者“为什么这个PHP不输出这个HTML/JS源代码?”而不是“为什么PHP生成的HTML/JS源代码不符合我的期望?” – Quentin 2010-12-02 09:08:03
**危险**:您的SQL注入安全漏洞!不要通过将包含unsanitized`$ _POST`数据的字符串粘在一起来构建SQL查询! http://bobby-tables.com/ – Quentin 2010-12-02 09:11:04