<php+mysql>PHP基础,使用PHP访问表单数据
2015-12-24 09:46
771 查看
(《Head First PHP & MySQL》学习记录)
![](https://img-blog.csdn.net/20151224094803936?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0<br/>4000<br/>JBQkFCMA==/dissolve/70/gravity/Center)
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:
php是工作于服务器端的,浏览器无法处理,所以要正常运行这个代码需要在计算机上搭建服务器,具体操作见:
<php+mysql>Mac配置APACHE+PHP+MYSQL+PHPMYADMIN http://blog.csdn.net/qq_17615475/article/details/50384817
然后将下载的代码放进上文中配置的用户级目录,在浏览器中输入localhost/文件夹/report.html地址来运行。
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地址来运行。
相关文章推荐
- PHP 常用的header头部定义汇总
- PHP面向对象编程——深入理解方法重载与方法覆盖(多态)
- php采用session实现防止页面重复刷新
- php项目打包
- PHP表单的验证--来自w3c
- PHP+Mysql日期时间如何转换(UNIX时间戳和格式化日期)
- php webservice应用
- 用php判断时间戳来输出刚刚,分钟前,小时前昨天和时间
- php采用session实现防止页面重复刷新
- PHP面向对象编程之深入理解方法重载与方法覆盖(多态)
- 深入浅析php json 格式控制
- PHP下SSL加密解密、验证、签名方法(很简单)
- php实现异步数据调用的方法
- 4种PHP异步执行的常用方式
- PHP文件上传问题汇总(文件大小检测、大文件上传处理)
- 纯PHP代码实现支付宝批量付款
- PHP实现文件上传和多文件上传
- 在openSUSE42.1下编译安装PHP7 的方法
- 通过PHP自带的服务器来查看正则匹配结果的方法
- Yii2 删除