php第一天post

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>

<?php 
$n1 = "";
$n2 = "";
$result = "";
if( isset($_POST['num1']) ) 
{
	$n1 = $_POST['num1'];
	$n2 = $_POST['num2'];
	$result = $n1 + $n2;
	//echo "<br>计算结果为:" , $result;
}
 ?>

<body>
	<!-- action留空表示提交给自己(本页) -->
	<form action="" method="post">

		数字1<input type="text" name="num1" value="<?php echo $n1;  ?>">
		<!-- 有兴趣有时间的同学,可以把这个"+"用一个select来代替,用户可以选择加减乘除 -->
		+
		数字2<input type="text" name="num2" value="<?php echo $n2;  ?>">
		<input type="submit" value="=">
		<input type="text" name="result" value="<?php echo $result;  ?>">
	</form>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>

<?php 
$n1 = "";
$n2 = "";
$result = "";
if( isset($_REQUEST['num1']) ) 
{
	$n1 = $_REQUEST['num1'];
	$n2 = $_REQUEST['num2'];
	$result = $n1 + $n2;
	//echo "<br>计算结果为:" , $result;
	
	echo "<br>用户名:", $_REQUEST['userName'];
	echo "<br>你的账户余额为:0,请交费。。。";
}
 ?>

<body>
	<form action="09request_form.php?id=10&userName=zhangsan" method="post">
		<!-- 这种表单形式,才可以让一个表单同时提交get数据和post数据:
		action中的地址里的?后的数据是get数据
		form表单中的各个表单项,就是post数据! -->
		数字1<input type="text" name="num1" value="<?php echo $n1;  ?>">
		+
		<input type="text" name="num2" value="<?php echo $n2;  ?>">
		<input type="submit" value="=">
		<input type="text" name="result" value="<?php echo $result;  ?>">
	</form>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/qq_34608447/article/details/90044102