PHP+MySQL开发小项目的集合笔记(一)提交表单操作数据库

环境为:phpStudy 2016 php-5.4.45

数据库环境:http://localhost:81/phpMyAdmin/index.php

连接环境:E:\phpStudy\WWW\easyPHP\increase.html

所有内存都放在easyPHP文件夹内。

连接:http://localhost:81/easyPHP/increase.html

需求:提交表单,写入数据库。提交查看,查看数据库。提交删除,删除数据库。简单的单条数据即可。

预估时间:一天

MySQL脚本:

CREATE TABLE 'message' (
 'id' tinyint(1) NOT NULL auto_increment,
 'user' varchar(25) NOT NULL,
 'position' varchar(50) NOT NULL,
 'content' tinytext NOT NULL,
 'lastdate' timestamp NOT NULL,
 PRIMARY KEY ('id')
)ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

 实现:建立data1的数据库,建立message的表单类型为utf8_general_ci,创建id类型tinyint(1),创建user类型varchar(25),创建position类型varchar(50),创建content类型tinytext,创建lastdate类型timestamp。设置主键为id。设置id为逐一递增(因为只有一条记录,所以然并卵)。

dao.php脚本:

实现:连接数据库,在连接失败后提示failed at first,和error代码。选择data1的数据库。设置查询utf8。

delete.php脚本:

alert('Delete Success');location.href='increase.html';";
}
?>

实现:引入dao.php。实现删除id为0的数据,如果成功使用JavaScript提示出Success并跳转回increase.html

drawing.css使用css渲染页面:

form{
margin:0px;
padding:0px;
}
body{
font-size:10px;
line-height:13px;
backgroud-color:#b5e1e7;
}

textarea{
font-size:10px;
border:1px solid #9999CC;
padding:5px;
}
td{
line-height:16px;
font-size:10px;
font-family:"Microsoft YaHei", "΢ÈíÑźÚ";
}
a:link{
text-deoration:none;
color:#000000;
}

increase.php点击submit后把数据传到数据库

alert('Submit Success');location.href='increase.html';";
}
?>

实现:$_POST["submit"]出现后执行添加功能并提示添加成功,返回increase.html页面。

前台页面increase.html有多个选择按钮




    
    Submit and Display
    
    



Area
Display 

Who you are:
What do you do:
How do you do it:

实现:引入increase.php和drawing.css。点击Display字体后跳转到list.php页面。输入表单,然后提交action为“submit”。点击DELETE按钮提交action为delete.php页面。

list.php最复杂的读取数据库并显示到页面,因为是跳转不用ajax,只能用拼接php和html。




    
    
    Submit and Display
    



user: position:
content:
time:
Return: Return

实现:引入dao.php和drawing.css。建立单一表格,然后把从数据库查到的数据装入到html标签内。因为没有多数据,所以不需要循环。

 

 

 

 

 

 

你可能感兴趣的:(PHP+MySQL小项目)