php调用javascript变量,echo显示已经赋值,但不能存入数据库,如果在PHP中对变量赋值就可以,为什么? 100
JavascriptPHP数据库修改标签<html><head><linkhref="./css/main.css"rel="stylesheet"type="text/...
JavascriptPHP数据库 修改标签
<html>
<head>
<link href="./css/main.css" rel="stylesheet" type="text/css" media="screen" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<script type="text/javascript">
var temp="77777"
</script>
<?php
$today = date("Ymd");
$temp="<script type=text/javascript>document.write(temp)</script>";
$con = mysql_connect(SAE_MYSQL_HOST_M.':'.SAE_MYSQL_PORT,SAE_MYSQL_USER,SAE_MYSQL_PASS);if(!$con){ die('could not connect:'.mysql_error()); }mysql_select_db(SAE_MYSQL_DB,$con);
mysql_query("set names UTF-8");
mysql_query("SET CHARACTER SET utf8");
mysql_query("SET COLLATION_CONNECTION='utf8_general_ci'");
$tem = strval(trim($temp));
echo $tem;
$query="INSERT INTO sh601390T (orderdate,stockprice) values ($today,$tem)";
mysql_query($query);
mysql_close($con);
?>
</body>
</html>
补充:$today 可以插入数据库,$tem不可以,如果不调用javascript,直接赋值给$stem,可以插入,说明php调用javascript变量有问题,但是echo $tem确已经赋值成功,为什么呢?请给我源码,我知道ajax能实现,请援助,谢谢。 展开
<html>
<head>
<link href="./css/main.css" rel="stylesheet" type="text/css" media="screen" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<script type="text/javascript">
var temp="77777"
</script>
<?php
$today = date("Ymd");
$temp="<script type=text/javascript>document.write(temp)</script>";
$con = mysql_connect(SAE_MYSQL_HOST_M.':'.SAE_MYSQL_PORT,SAE_MYSQL_USER,SAE_MYSQL_PASS);if(!$con){ die('could not connect:'.mysql_error()); }mysql_select_db(SAE_MYSQL_DB,$con);
mysql_query("set names UTF-8");
mysql_query("SET CHARACTER SET utf8");
mysql_query("SET COLLATION_CONNECTION='utf8_general_ci'");
$tem = strval(trim($temp));
echo $tem;
$query="INSERT INTO sh601390T (orderdate,stockprice) values ($today,$tem)";
mysql_query($query);
mysql_close($con);
?>
</body>
</html>
补充:$today 可以插入数据库,$tem不可以,如果不调用javascript,直接赋值给$stem,可以插入,说明php调用javascript变量有问题,但是echo $tem确已经赋值成功,为什么呢?请给我源码,我知道ajax能实现,请援助,谢谢。 展开
1个回答
2015-09-29
展开全部
$query="INSERT INTO sh601390T (orderdate,stockprice) values ('$today','$tem')";
碰到问题要自己调试,没谁欠你的。把上面的一段改下
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询