$conn= @odbc_connect ($odbcDsn, $odbcUser, $odbcPass) or die("不能连接到数据库服务器!");$pfocus='<script language=javascript> document.write(document.form1.hiddes.value); </script>';
$pkeywords='<script language=javascript>document.write(document.form1.hidkey.value); </script>';echo $pfocus; $Query ="INSERT INTO record(focus,keywords) values('$pfocus','$pkeywords')";
$result = odbc_exec($conn,$Query);
问题:
echo $pfocus;输出到页面上的为正常的字符串,比如---“pk university”;
但是执行完 $result = odbc_exec($conn,$Query); 后数据库中的表里的内容却是字符串----“<script language=javascript>document.write(document.form1.hidkey.value); </script>”
请问这是为什么,并且如何让写入到表里的值变为正常值???????
$pkeywords='<script language=javascript>document.write(document.form1.hidkey.value); </script>';echo $pfocus; $Query ="INSERT INTO record(focus,keywords) values('$pfocus','$pkeywords')";
$result = odbc_exec($conn,$Query);
问题:
echo $pfocus;输出到页面上的为正常的字符串,比如---“pk university”;
但是执行完 $result = odbc_exec($conn,$Query); 后数据库中的表里的内容却是字符串----“<script language=javascript>document.write(document.form1.hidkey.value); </script>”
请问这是为什么,并且如何让写入到表里的值变为正常值???????
-------------执行了document.write了
如何让写入到表里的值变为正常值???????
-------------------------
不太明白你的需求
$pfocus=' <script language=javascript> document.write(document.form1.hiddes.value); </script>';
单引号只是字符串。$pfocus=“<script language=javascript> document.write(document.form1.hiddes.value); </script>”;
双引号是执行。
不过貌似不应该这样执行
但是在试图把这个值写到数据库里的时候却解释成了javascript代码。
怎么才能把具体的值写到数据库的表里呢??
我想把html的meta信息写到数据库中
先把meta信息通过javascript写到了表单隐藏控件里
然后再用这种方法去读到数据库中,
由于所有的操作都在一个页面所有没有表单提交的内容。
现在我知道了变量里只是保存了字符串,
问怎么能获取其显示的值,写到数据库里呢???
其肯定是从某个变量过来的。比如title那即然如此,你何必考虑如何从html代码中获得变量呢?
为何不直接从其上级来源处获得变量呢?如果非要从html源码中获取变量,可以用正则匹配的方式进行查找。
什么是后台? -> 服务器你写的代码都是在后台做的,在后台处理的时候已经脱离了前台,前台往后台传数据只能
通过GET或者POST.通常的手段是表单提交或者Ajax.
PHP的代码只是在服务器端运行,运行结果变成HTML传到前台而已.
所以你想用PHP和还没有生成的HTML交互是不可能的.