html传值给php
① html传输到php数据
这个需要使用php中的$_REQUEST["code"]全局变量的方式,据可以获取到HTML传输过来的数据了。
② html页面中定义一个变量,怎么把这个变量传递到php页面中,并在php页面中接受
你可以把这个变量放在form中,变量名是一个input标签的name属性值,变量值是这个input标签的value属性值,例子如下:
你的html中定义了变量a="123":
<html><head></head>
<body>
<form action="test.php" method="post"><input name="a" value="123"/><input type="submit" value="Submit" /></form>
</body></html>
你的test.php:
<?php echo $_POST["a"];?>
点击按钮之后就会把变量的a的值传给test.php,并打印到页面上。
还有其他的很多方法,比如用ajax的异步传输等等,例子网上一搜一大堆,我就不给你写例子了。
③ html页面提交给php并执行php里面的代码
<html>
<heads
<title>
leilei
<Ititle>
<body>
<form method="post" action="input.php">
<p>您的姓名<input type="text" name="name" size="20"></p>
<p>您的性别<input type="radio"value="1"name="male" checked>男生</p>
<input type="radio" value="0"name="male" checked>女生</p>
<p>您的电邮<input type="text" name="email" size="20"></p>
<p> <textarea rows="9" name="info" cols="35"> </textarea > </p >
<input type="submit" vaiue="提交"name="B1"><input type="reset"
value="重新设定" name="B2"> </p>
</form>
</body>
</html>
input.php
④ html如何向php中post数据
通过form表单提交,method为post类型。
如果按照地址栏方式传参(这种http://xxx.xxx.xxx/xxx.php?user=user&pwd=pwd),php就得用$_GET方式接收传过来的值
⑤ html传值给php
<html>
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<title>无标题文档</title>
</head>
<body>
<formaction=""method="get">
Name:<inputtype="text"name="name"/>
<inputtype="submit"/>
</form>
<?php
$name=$_GET['name'];
echo"欢迎你:".$name;
?>
</body>
</html>
⑥ HTML代码 和PHP代码在一个页面。怎么把html里的表单数据提交给php
test.php页面
判断该页是否提交,如果提交了,就按照正常的接受数据来就行了。
<?php
if($_POST){
$words=$_POST["words"];
if($words){
echo"收到";
}
}
?>
<!DOCTYPEhtml>
<htmllang="en">
<head>
<metacharset="UTF-8">
<title>Document</title>
</head>
<body>
<formaction="test.php"method="post">
<inputtype="text"name="words">
<inputtype="submit"name=""value="提交">
</form>
</body>
</html>