<php+mysql>PHP基础,使用PHP访问表单数据

(《Head First PHP & MySQL》学习记录)


HTML5:

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>report</title>
<link rel="stylesheet" href="report.css" />
</head>
<h1>Aliens Abducted Me - Report an Abduction</h1>
<p>Share your story of alien abduction:</p>
<form method="post" action="report.php">
<label for="firstname">First Name: </label>
<input type="text" id="firstname" name="firstname" /><br />
<label for="lastname">Last Name: </label>
<input type="text" id="lastname" name="lastname" /><br />
<label for="email">Email: </label>
<input type="text" id="email" name="email" /><br />
<label for="when">When did it happened: </label>
<input type="text" id="when" name="when" /><br />
<label for="timelast">How long were you gone:</label>
<input type="text" id="timelast" name="timelast" /><br />
<label for="fang">Have you seen my dog Fang?</label>
Yes<input type="radio" id="fang" name="fang" value="yes" />
No<input type="radio" id="fang" name="fang" value="no" /><br />
<label for="anythingelse">Anything else to add?</label>
<input type="text" id="anythingelse" name="anythingelse" /><br />
<input type="submit" name="submit" value="Report Abduction" />
</form>
<body>
</body>
</html>
PHP:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>report</title>
</head>

<body>
	<h2>Aliens Abducted Me - Report an Abduction</h2>
    <?php
		$name=$_POST['firstname'].' '.$_POST['lastname'];
		$when=$_POST['when'];
		$timelast=$_POST['timelast'];
		$fang=$_POST['fang'];
		$anythingelse=$_POST['anythingelse'];
		$email=$_POST['email'];
		
		$to='changingvan@163.com';
		$subject='Aliens abducted me';
		$msg="$name was abducted $when and was gone for $timelast.\n".
			"Fang spotted: $fang.\n".
			"Other info: $anythingelse.\n";
		mail($to,$subject,$msg,'Form'.$email);
		
		echo 'Thanks for submitting the form. <br/>';
		echo 'You were abducted '.$when;
		echo 'and gone for '.$timelast.'<br/>';
		echo 'You saw Fang? '.$fang.'<br/>';
		echo 'Other information: '.$anythingelse.'<br/>';
		echo 'Your email address is '.$email;
	?>
</body>
</html>
代码下载: http://download.csdn.net/detail/qq_17615475/9374869

php是工作于服务器端的,浏览器无法处理,所以要正常运行这个代码需要在计算机上搭建服务器,具体操作见:

<php+mysql>Mac配置APACHE+PHP+MYSQL+PHPMYADMIN http://blog.csdn.net/qq_17615475/article/details/50384817

然后将下载的代码放进上文中配置的用户级目录,在浏览器中输入localhost/文件夹/report.html地址来运行。


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值