#1 add life to static pages && connect to MySQL
由于实验室 Project 中需要用到PHP, 之前也没接触过 PHP, 因此把 编程入门 《Head Fist PHP & MySQL 》找来花了四五天快速过了一遍。
现在想把书中的系统东西总结一下,方便日后的查询。
chapter01 & chapter02 主要简单介绍了 PHP 以及 MySQL 数据库的基本语句,有基础的同学随便翻翻就懂了。
虽然简单,但是它仍然 构建出了一个 基本完整的网站的 框架, 这也是我觉得 Head First 系列很优秀的地方。
前两章主要大体介绍了 PHP 和 MySQL 数据库的基本操作,配套的书中在这两章中通过 PHP 和 MySQL 搭建了一个最简单的 WebSite。 为了练习英文我就用 英文写啦:
You can following the steps to finish this lab :
1. You need to install Apache, PHP, MySQL on you Server(Mine is Linux)
2. Create a new folder, name it Chapter01 or whatever, edit the following files in the folder:
/*** report.html ***/
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Aliens Abducted Me - Report an Abduction</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<h2>Aliens Abducted Me - Report an Abduction</h2> <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">What is your email address?</label>
<input type="text" id="email" name="email" /><br />
<label for="whenithappened">When did it happen?</label>
<input type="text" id="whenithappened" name="whenithappened" /><br />
<label for="howlong">How long were you gone?</label>
<input type="text" id="howlong" name="howlong" /><br />
<label for="howmany">How many did you see?</label>
<input type="text" id="howmany" name="howmany" /><br />
<label for="aliendescription">Describe them:</label>
<input type="text" id="aliendescription" name="aliendescription" size="32" /><br />
<label for="whattheydid">What did they do to you?</label>
<input type="text" id="whattheydid" name="whattheydid" size="32" /><br />
<label for="fangspotted">Have you seen my dog Fang?</label>
Yes <input id="fangspotted" name="fangspotted" type="radio" value="yes" />
No <input id="fangspotted" name="fangspotted" type="radio" value="no" /><br />
<img src="fang.jpg" width="100" height="175"
alt="My abducted dog Fang." /><br />
<label for="other">Anything else you want to add?</label>
<textarea id="other" name="other"></textarea><br />
<input type="submit" value="Report Abduction" name="submit" />
</form>
</body>
</html>
/*** style.css ***/
form label {
display: inline-block;
width: 225px;
font-weight: bold;
}
you can put these files in diffierent folders. that would be a good habit. I am so lazy so I put them together in one folder(Mine is cha01).
3. Create a database with the MySQL. User this database. Create a table in the database.
Use the command :
mysql -u root -p; #you can login in MySQL as root
create database headfirst; #create a database named headfirst;
use database headfirst; #use this database;
then you need to create a table with the following scripts:
CREATE TABLE aliens_abduction (
first_name varchar(30),
last_name varchar(30),
when_it_happened varchar(30),
how_long varchar(30),
how_many varchar(30),
alien_description varchar(100),
what_they_did varchar(100),
fang_spotted varchar(10),
other varchar(100),
email varchar(50)
);
4. Now you have finish the HTML file on the Server, which will send to the client(Broswer) , and people will use this file to get access to your Server.
and you have created a database on the Server, which will store the data the from client all over the world.
Then what you need is to set a PHP file on the Server to handle the requests from the client and put the data in the requests into the database.
Now, you can see the PHP file on the Server is just like a bridge between the client and server.
/*** report.php ***/
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Aliens Abducted Me - Report an Abduction</title>
</head>
<body>
<h2>Aliens Abducted Me - Report an Abduction</h2> <?php
$first_name = $_POST['firstname'];
$last_name = $_POST['lastname'];
$when_it_happened = $_POST['whenithappened'];
$how_long = $_POST['howlong'];
$how_many = $_POST['howmany'];
$alien_description = $_POST['aliendescription'];
$what_they_did = $_POST['whattheydid'];
$fang_spotted = $_POST['fangspotted'];
$email = $_POST['email'];
$other = $_POST['other']; // echo "Hello"; $dbc = mysqli_connect('localhost', 'root', 'root', 'headfirst')
or die('Error connecting to MySQL server.'); $query = "INSERT INTO aliens_abduction(first_name, last_name,
when_it_happened, how_long, how_many, alien_description,
what_they_did, fang_spotted, other, email)
VALUES('$first_name', '$last_name', '$when_it_happened', '$how_long',
'$how_many','$alien_description', '$what_they_did', '$fang_spotted',
'$other', '$email')"; $result = mysqli_query($dbc, $query)
or die('Error querying databases'); mysqli_close($dbd); echo 'Thanks for submitting the form.<br />';
echo 'You were abducted ' . $when_it_happened;
echo ' and were gone for ' . $how_long . '<br />';
echo 'Number of aliens: ' . $how_many . '<br />';
echo 'Describe them: ' . $alien_description . '<br />';
echo 'The aliens did this: ' . $what_they_did . '<br />';
echo 'Was Fang there? ' . $fang_spotted . '<br />';
echo 'Other comments: ' . $other . '<br />';
echo 'Your email address is ' . $email;
?> </body>
</html>
Then you have finished a basic WebSite. If you put it on to the internet, everyone can access it through the internet. Thats cool!
#1 add life to static pages && connect to MySQL的更多相关文章
- 解决Can't connect to MySQL server on 'localhost' (10048)
解决Can't connect to MySQL server on 'localhost' (10048) 您使用的是Windows操作系统,此错误与一个注册表键值TcpTimedWaitDelay ...
- 2003-Can't connect to mysql server on localhost (10061)
mysql数据库出现2003-Can't connect to mysql server on localhost (10061)问题 解决办法:查看wampserver服务器是否启动,如果没有启动启 ...
- ERROR 2003 (HY000): Can't connect to MySQL server on 'ip address' (111)的处理办法
远程连接mysql数据库时可以使用以下指令 mysql -h 192.168.1.104 -u root -p 如果是初次安装mysql,需要将所有/etc/mysql/内的所有配置文件的bind-a ...
- can't connect to mysql server on 'localhost'(10061)
在linux下安装Navicat,想说在windows下试一试phpmyadmin之外的mysql图形工具. 显示下载安装了mysql workbench,链接成功.然后又弄了一下输入法重启,想说试一 ...
- MySQL问题记录--Can't connect to MySQL server on localhost (10061)解决方法
本文mysql的安装环境为win7 64位,mysql版本为MySQL5.7 问题描述:在命令行输入 mysql -u root -p 登录mysql,返回"Can't connect to ...
- ruby使用DBI连接MySQL数据库发生异常:in `error': Can't connect to MySQL server on 'localhost' (10061) (DBI::DatabaseError)
Ruby使用DBI连接MySQL数据库一般为: require "dbi" dbh = DBI.connect("dbi:Mysql:test:localhost&quo ...
- mysqlnd cannot connect to MySQL 4.1+
phpMyAdmin - error #2000 - mysqlnd cannot connect to MySQL 4.1+ using the old insecure authenticatio ...
- mysql中Can't connect to MySQL server on 'localhost' (10061)
Can't connect to MySQL server on 'localhost' (10061) 第一问题有两个解决方案: 1)没有启动sql服务,以下是具体步骤: 右键-计算机-管理-服务和 ...
- 连接mysql问题 mysqlnd cannot connect to MySQL 4.1+ using old authentication
第一篇:PHP5.3开始使用MySqlND作为默认的MySql访问驱动,而且从这个版本开始将不再支持使用旧的用户接口链接Mysql了,你可能会看到类似的提示: #2000 - mysqlnd cann ...
随机推荐
- 项目打包发布到tomcat中,中文出现乱码
先吐槽一下,花了我3个小时,心累 本地运行正常,发布时maven插件里要加utf-8编码 https://blog.csdn.net/testcs_dn/article/details/4558379 ...
- 《javascript设计模式》笔记之第十二章:装饰者模式
一.装饰者模式的作用 为函数或者对象的方法添加一些行为. 二.装饰者模式的原理 装饰者模式不是直接修改对象,而是以要修改的对象为基础,新建一个对象.不过这个新建的对象看起来就像在原对象的基础上 ...
- Jquery3
动画 动画动画效果一:show(时间),hide(时间)说明:时间的单位为毫秒方法toggle(时间):使用动画切换显示与隐藏动画效果二:slideDown(时间),slideUp(时间)切换:sli ...
- html 获取和写入cookie的 方法
//取Cookie的值 function getCookie(cookie_name) { var allcookies = document.cookie; v ...
- 同步Windows 10与MIUI 9来完成你的日程安排
我们都知道,outlook可以有效管理你的日程.而MIUI 9在负一屏上全新改版了界面,变得更加全面人性化.接下来我将展示几种方法,让你的Windows 10与MIUI 9协同工作. 一.outloo ...
- Windows UEFI 安装策略的一个细节
在计算机已连接任何带Windows Boot Manager的硬盘的时候,系统自己不会创建EFI分区,而是用之前的
- ThinkPHP笔记——开启debug调试模式
debug+trace模式可以查看开发过程中TP的错误信息,可以更好地帮助开发者debug.但是debug模式的开启还不是简单的在配置文件中中设置就可以的,经过查资料摸索,找到一种有效的方法. 首先在 ...
- [神经网络]一步一步使用Mobile-Net完成视觉识别(三)
1.环境配置 2.数据集获取 3.训练集获取 4.训练 5.调用测试训练结果 6.代码讲解 本文是第三篇,获取tfboard训练集. 前面我们拿到了所有图片对应的标注信息的xml文件,现在我们需要先把 ...
- [CV笔记]OpenCV机器学习笔记
KNN算法: 目的是分类,具体过程为,先训练,这个训练我估计只是对训练数据进行一个存储,knn测试的过程是根据测试样例找出与这个样例的距离最近的k个点,看这k个点中哪个分类所占的比例比较多,那么这个样 ...
- HTML5新增的音频标签、视频标签
我们所说的H5就是我们所说的HTML5中新增的语言标准 一.音频标签 在HTML5当中有一个叫做audio的标签,可以直接引入一段音频资源放到我们的网页当中 格式: <audio autopla ...