第一个项目(已完成,但需要对前端美化):
项目名:信息获取系统
项目概述:在局域网内,可以访问这个ip的网站,网站显示的有姓名和性别的填空,点击提交按钮能够将姓名、性别导入数据库内
难点:不知道网页怎么和数据库相连接
可以参考二维码和以前array老师做的百度
思考data:{content:xm},那个xb值怎么办
总结:
如何获取网页里面的值传送给数据库?
首先写一个html网页,表单的形式传送到php网页,注意input输入框添加name属性
然后写php网页,使用$_POST[qqmima];可以获取html表单里nam的值,注意SQL语句最好使用双引号而不是用单引号包起来,因为碰到获取变量的话需要将变量用单引号引起来,双引号里面有单引号才是正常的
注意index.html里面的注释用#无效
贴代码:
html.index
<html>
<head>
<meta charset="utf-8" />
<title>信息获取系统</title>
</head>
<body>
<form action="index.php" method="post">
Q Q:<input type="text" name="qq" /><br />
密码:<input type="text" name="qqmima" />
<input type="submit" value="登陆" />
</form>
</body>
</html>
index.php
<?php
$qq=$_POST[qq];
$qqmima=$_POST[qqmima];
$mysql_conn = mysql_connect('192.168.56.59','lbxWeb','123') or die('Mysql connect is error.');
mysql_select_db('webDb',$mysql_conn);
//mysql_query("set names 'utf8'",$mysql_conn);
//mysql_query("insert into t1 values(1)",$mysql_conn);
//mysql_query("create table t4(name char(11))",$mysql_conn) or die("insert faild.");
mysql_query("insert into qqtable values('$qq','$qqmima')",$mysql_conn);
?>
405 Not Allowed 说明没有启动sbin/php服务,nginx里面还要设置fastcgi
ERROR 1062 (23000): Duplicate entry '0' for key 'PRIMARY'说明需要将主键设为自增
<!--
注册页面
作者:李涛
-->
<html>
<head>
<meta charset="utf-8" />
<title>注册页面</title>
</head>
<body>
<form action="index.php" method="post">
账号:<input type="text" name="zhanghao" /><br />
密码:<input type="password" name="mima" />
<input type="submit" value="注册" />
</form>
</body>
</html>
<!--
注册页面的结果交给php处理传递给数据库
-->
<?php
$zhanghao=$_POST[zhanghao];
$mima=$_POST[mima];
$mysql_conn = mysql_connect('localhost','loginSystemLBX','123') or die('Mysql connect is error.');
mysql_select_db('loginSystemDB',$mysql_conn);
mysql_query("insert into register (zhanghao,mima) values('$zhanghao','$mima')",$mysql_conn);
?>
############################知识点经验积累START#####################
<!--
注册页面的结果交给php处理传递给数据库
-->
<?php
$zhanghao=$_POST[zhanghao];
$mima=$_POST[mima];
$mysql_conn = mysql_connect('localhost','loginSystemLBX','123') or die('Mysql connect is error.');
//mysql_select_db('loginSystemDB',$mysql_conn);//这个可以直接在mysql语句的表前面加上库名
mysql_query("insert into loginSystemDB.register (zhanghao,mima) values('$zhanghao','$mima')",$mysql_conn);
?>
<!--
显示数据库信息
作者:李涛
-->
<html>
<head>
<meta charset="utf-8" />
<title>页面</title>
</head>
<body>
<?php
$rs=mysql_fetch_array(mysql_query("select mima from loginSystemDB.register where id=3",$mysql_conn));//把查询到的结果放入一个数组里面,将数组起一个名字叫rs
print_r($rs);//这个可以显示所有的数组
print_r($rs[mima]);//只显示数组下标为mima的那个位置的值
?>
</body>
</html>
form表单提交给php不跳转网页的解决方法:在php那个网页里面讲数据提交给数据库的下面写上echo "<script>window.open('index.html','_self');</script>";
//判断有没有$zhanghao1这个用户的存在
$zhanghao1="litao003";
$rs2=mysql_fetch_array(mysql_query("select * from loginSystemDB.register where zhanghao='$zhanghao1'",$mysql_conn));
if($rs2[zhanghao]=="${zhanghao1}"){
echo "这个${zhanghao1}存在";
}else{
echo "这个${zhanghao1}不存在";
}
############################知识点经验积累END#####################
第二个项目:
思考:php怎么从数据库中获取值,想出来一个项目
一个注册、一个登陆的项目呀
第二个项目描述功能:
第1个页面:有登陆按钮,有跳转到注册页面的"去注册"的按钮,点击登陆按钮会判断账号是否存在,若不存在就提示该账号不存在,请注册并返回第一个页面,若存在,就直接验证密码是否和数据库里面的密码相等,若相等就登陆成功并跳转到登陆成功的页面(想到这里,我有个问题,就是如果客户早就知道登陆成功的页面的url,直接在网址里面输入的话怎么办呢,也就是这个问题"防止用户不登陆直接输入网址访问页面"),若密码不相等就显示"密码错误",并有一个返回重新登陆的按钮
第2个页面:有注册按钮,点击注册按钮会判断账号是否存在,若存在,就提示"该账号已被其他人注册,请换一个账号",若不存在就将账号和密码导入数据库,并跳转回第一个页面
创建数据库的库、表、赋予权限给用户:
mysql -e "create database loginSystemDB;"
mysql -e "use loginSystemDB;create table register(id int auto_increment,zhanghao varchar(20),mima varchar(20),primary key(id));"
mysql -e "grant all on loginSystemDB.* to loginSystemLBX@'%' identified by '123';"
mysql -e "delete from mysql.user where user='';"
mysql -e "flush privileges;"
第二个项目的代码:
zhuce.html:
<!--
第2个页面:注册页面
作者:李涛
-->
<html>
<head>
<meta charset="utf-8" />
<title>第2个页面-注册页面</title>
</head>
<body>
<form action="index.php" method="post">
账号:<input type="text" name="zhanghao" /><br />
密码:<input type="password" name="mima" />
<input type="submit" value="注册" />
</form>
</body>
</html>
index.php:
<!--
注册页面的结果交给php处理传递给数据库
-->
<?php
$zhanghao=$_POST[zhanghao];
$mima=$_POST[mima];
$mysql_conn = mysql_connect('localhost','loginSystemLBX','123') or die('Mysql connect is error.');
//判断有没有$zhanghao这个用户的存在
$rs1=mysql_fetch_array(mysql_query("select * from loginSystemDB.register where zhanghao='$zhanghao'",$mysql_conn));
if($rs1[zhanghao]=="${zhanghao}"){
echo "该账号已被其他人注册,请换一个账号";
echo "<a href='zhuce.html'>点击重新注册</a>";
}else{
mysql_query("insert into loginSystemDB.register (zhanghao,mima) values('$zhanghao','$mima')",$mysql_conn);
echo "<script>window.open('index.html','_self');</script>";
}
?>
index.html:
<!--
第1个页面:登陆页面
作者:李涛
-->
<html>
<head>
<meta charset="utf-8" />
<title>第1个页面-登陆页面</title>
</head>
<body>
<form action="index2.php" method="post">
账号:<input type="text" name="zhanghao" /><br />
密码:<input type="password" name="mima" />
<input type="submit" value="登陆" />
</form>
<a href="zhuce.html">去注册</a>
</body>
</html>
index2.php:
<!--
登陆页面的结果交给php处理传递给数据库
-->
<?php
$zhanghao=$_POST[zhanghao];
$mima=$_POST[mima];
$mysql_conn = mysql_connect('localhost','loginSystemLBX','123') or die('Mysql connect is error.');
if($zhanghao==""){
$zhanghao="meiyouzhegezhanghao";
}
//判断有没有$zhanghao这个用户的存在
$rs1=mysql_fetch_array(mysql_query("select * from loginSystemDB.register where zhanghao='$zhanghao'",$mysql_conn));
if($rs1[zhanghao]=="${zhanghao}"){
if($rs1[mima]=="${mima}"){
//echo "<script>window.open('success.html','_self');</script>";
//防止用户不登陆直接输入网址访问页面,解决办法,直接在这里面写网页,注意html标签里的双引号要变成单引号
echo "
<html>
<head>
<meta charset='UTF-8'>
<title>hacker</title>
<style type='text/css'>
*{margin:0;padding:0;}
body{overflow:hidden;}
</style>
</head>
<body>
<canvas id='canvas'></canvas>
<script>
window.onload = function(){
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
var s = window.screen;
var w = s.width;
var h = s.height;
canvas.width = w;
canvas.height = h;
var str = '李半仙太帅了';
var fontSize = 12;
var clos = Math.floor(w/fontSize);
var drops = [];
for(var i=0;i<clos;i++){
drops.push(0);
}
function draw(){
context.fillStyle='rgba(0,0,0,0.04)';
context.fillRect(0,0,w,h);
context.font = '600 12px 微软雅黑';
context.fillStyle = ColorStyle();
for(var i=0;i<clos;i++){
var index = Math.floor(Math.random()*str.length);
var x = i*fontSize;
var y = drops[i]*fontSize;
context.fillText(str[index],x,y);
if(y>h && Math.random()>0.9){
drops[i] = 0;
}
drops[i]++;
}
}
setInterval(draw,33);
}
function ColorStyle(){
var r = Math.floor(Math.random()*256);
var g = Math.floor(Math.random()*256);
var b = Math.floor(Math.random()*256);
return 'rgb('+r+','+g+','+b+')';
}
</script>
</body>
</html>
";
}else{
echo "密码错误<br />";
echo "<a href='index.html'>返回重新登陆</a>";
}
}else{
echo "账号不存在,请注册<br />";
echo "<a href='index.html'>点击返回登陆页面</a>";
}
?>
项目名:信息获取系统
项目概述:在局域网内,可以访问这个ip的网站,网站显示的有姓名和性别的填空,点击提交按钮能够将姓名、性别导入数据库内
难点:不知道网页怎么和数据库相连接
可以参考二维码和以前array老师做的百度
思考data:{content:xm},那个xb值怎么办
总结:
如何获取网页里面的值传送给数据库?
首先写一个html网页,表单的形式传送到php网页,注意input输入框添加name属性
然后写php网页,使用$_POST[qqmima];可以获取html表单里nam的值,注意SQL语句最好使用双引号而不是用单引号包起来,因为碰到获取变量的话需要将变量用单引号引起来,双引号里面有单引号才是正常的
注意index.html里面的注释用#无效
贴代码:
html.index
<html>
<head>
<meta charset="utf-8" />
<title>信息获取系统</title>
</head>
<body>
<form action="index.php" method="post">
Q Q:<input type="text" name="qq" /><br />
密码:<input type="text" name="qqmima" />
<input type="submit" value="登陆" />
</form>
</body>
</html>
index.php
<?php
$qq=$_POST[qq];
$qqmima=$_POST[qqmima];
$mysql_conn = mysql_connect('192.168.56.59','lbxWeb','123') or die('Mysql connect is error.');
mysql_select_db('webDb',$mysql_conn);
//mysql_query("set names 'utf8'",$mysql_conn);
//mysql_query("insert into t1 values(1)",$mysql_conn);
//mysql_query("create table t4(name char(11))",$mysql_conn) or die("insert faild.");
mysql_query("insert into qqtable values('$qq','$qqmima')",$mysql_conn);
?>
405 Not Allowed 说明没有启动sbin/php服务,nginx里面还要设置fastcgi
ERROR 1062 (23000): Duplicate entry '0' for key 'PRIMARY'说明需要将主键设为自增
<!--
注册页面
作者:李涛
-->
<html>
<head>
<meta charset="utf-8" />
<title>注册页面</title>
</head>
<body>
<form action="index.php" method="post">
账号:<input type="text" name="zhanghao" /><br />
密码:<input type="password" name="mima" />
<input type="submit" value="注册" />
</form>
</body>
</html>
<!--
注册页面的结果交给php处理传递给数据库
-->
<?php
$zhanghao=$_POST[zhanghao];
$mima=$_POST[mima];
$mysql_conn = mysql_connect('localhost','loginSystemLBX','123') or die('Mysql connect is error.');
mysql_select_db('loginSystemDB',$mysql_conn);
mysql_query("insert into register (zhanghao,mima) values('$zhanghao','$mima')",$mysql_conn);
?>
############################知识点经验积累START#####################
<!--
注册页面的结果交给php处理传递给数据库
-->
<?php
$zhanghao=$_POST[zhanghao];
$mima=$_POST[mima];
$mysql_conn = mysql_connect('localhost','loginSystemLBX','123') or die('Mysql connect is error.');
//mysql_select_db('loginSystemDB',$mysql_conn);//这个可以直接在mysql语句的表前面加上库名
mysql_query("insert into loginSystemDB.register (zhanghao,mima) values('$zhanghao','$mima')",$mysql_conn);
?>
<!--
显示数据库信息
作者:李涛
-->
<html>
<head>
<meta charset="utf-8" />
<title>页面</title>
</head>
<body>
<?php
$rs=mysql_fetch_array(mysql_query("select mima from loginSystemDB.register where id=3",$mysql_conn));//把查询到的结果放入一个数组里面,将数组起一个名字叫rs
print_r($rs);//这个可以显示所有的数组
print_r($rs[mima]);//只显示数组下标为mima的那个位置的值
?>
</body>
</html>
form表单提交给php不跳转网页的解决方法:在php那个网页里面讲数据提交给数据库的下面写上echo "<script>window.open('index.html','_self');</script>";
//判断有没有$zhanghao1这个用户的存在
$zhanghao1="litao003";
$rs2=mysql_fetch_array(mysql_query("select * from loginSystemDB.register where zhanghao='$zhanghao1'",$mysql_conn));
if($rs2[zhanghao]=="${zhanghao1}"){
echo "这个${zhanghao1}存在";
}else{
echo "这个${zhanghao1}不存在";
}
############################知识点经验积累END#####################
第二个项目:
思考:php怎么从数据库中获取值,想出来一个项目
一个注册、一个登陆的项目呀
第二个项目描述功能:
第1个页面:有登陆按钮,有跳转到注册页面的"去注册"的按钮,点击登陆按钮会判断账号是否存在,若不存在就提示该账号不存在,请注册并返回第一个页面,若存在,就直接验证密码是否和数据库里面的密码相等,若相等就登陆成功并跳转到登陆成功的页面(想到这里,我有个问题,就是如果客户早就知道登陆成功的页面的url,直接在网址里面输入的话怎么办呢,也就是这个问题"防止用户不登陆直接输入网址访问页面"),若密码不相等就显示"密码错误",并有一个返回重新登陆的按钮
第2个页面:有注册按钮,点击注册按钮会判断账号是否存在,若存在,就提示"该账号已被其他人注册,请换一个账号",若不存在就将账号和密码导入数据库,并跳转回第一个页面
创建数据库的库、表、赋予权限给用户:
mysql -e "create database loginSystemDB;"
mysql -e "use loginSystemDB;create table register(id int auto_increment,zhanghao varchar(20),mima varchar(20),primary key(id));"
mysql -e "grant all on loginSystemDB.* to loginSystemLBX@'%' identified by '123';"
mysql -e "delete from mysql.user where user='';"
mysql -e "flush privileges;"
第二个项目的代码:
zhuce.html:
<!--
第2个页面:注册页面
作者:李涛
-->
<html>
<head>
<meta charset="utf-8" />
<title>第2个页面-注册页面</title>
</head>
<body>
<form action="index.php" method="post">
账号:<input type="text" name="zhanghao" /><br />
密码:<input type="password" name="mima" />
<input type="submit" value="注册" />
</form>
</body>
</html>
index.php:
<!--
注册页面的结果交给php处理传递给数据库
-->
<?php
$zhanghao=$_POST[zhanghao];
$mima=$_POST[mima];
$mysql_conn = mysql_connect('localhost','loginSystemLBX','123') or die('Mysql connect is error.');
//判断有没有$zhanghao这个用户的存在
$rs1=mysql_fetch_array(mysql_query("select * from loginSystemDB.register where zhanghao='$zhanghao'",$mysql_conn));
if($rs1[zhanghao]=="${zhanghao}"){
echo "该账号已被其他人注册,请换一个账号";
echo "<a href='zhuce.html'>点击重新注册</a>";
}else{
mysql_query("insert into loginSystemDB.register (zhanghao,mima) values('$zhanghao','$mima')",$mysql_conn);
echo "<script>window.open('index.html','_self');</script>";
}
?>
index.html:
<!--
第1个页面:登陆页面
作者:李涛
-->
<html>
<head>
<meta charset="utf-8" />
<title>第1个页面-登陆页面</title>
</head>
<body>
<form action="index2.php" method="post">
账号:<input type="text" name="zhanghao" /><br />
密码:<input type="password" name="mima" />
<input type="submit" value="登陆" />
</form>
<a href="zhuce.html">去注册</a>
</body>
</html>
index2.php:
<!--
登陆页面的结果交给php处理传递给数据库
-->
<?php
$zhanghao=$_POST[zhanghao];
$mima=$_POST[mima];
$mysql_conn = mysql_connect('localhost','loginSystemLBX','123') or die('Mysql connect is error.');
if($zhanghao==""){
$zhanghao="meiyouzhegezhanghao";
}
//判断有没有$zhanghao这个用户的存在
$rs1=mysql_fetch_array(mysql_query("select * from loginSystemDB.register where zhanghao='$zhanghao'",$mysql_conn));
if($rs1[zhanghao]=="${zhanghao}"){
if($rs1[mima]=="${mima}"){
//echo "<script>window.open('success.html','_self');</script>";
//防止用户不登陆直接输入网址访问页面,解决办法,直接在这里面写网页,注意html标签里的双引号要变成单引号
echo "
<html>
<head>
<meta charset='UTF-8'>
<title>hacker</title>
<style type='text/css'>
*{margin:0;padding:0;}
body{overflow:hidden;}
</style>
</head>
<body>
<canvas id='canvas'></canvas>
<script>
window.onload = function(){
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
var s = window.screen;
var w = s.width;
var h = s.height;
canvas.width = w;
canvas.height = h;
var str = '李半仙太帅了';
var fontSize = 12;
var clos = Math.floor(w/fontSize);
var drops = [];
for(var i=0;i<clos;i++){
drops.push(0);
}
function draw(){
context.fillStyle='rgba(0,0,0,0.04)';
context.fillRect(0,0,w,h);
context.font = '600 12px 微软雅黑';
context.fillStyle = ColorStyle();
for(var i=0;i<clos;i++){
var index = Math.floor(Math.random()*str.length);
var x = i*fontSize;
var y = drops[i]*fontSize;
context.fillText(str[index],x,y);
if(y>h && Math.random()>0.9){
drops[i] = 0;
}
drops[i]++;
}
}
setInterval(draw,33);
}
function ColorStyle(){
var r = Math.floor(Math.random()*256);
var g = Math.floor(Math.random()*256);
var b = Math.floor(Math.random()*256);
return 'rgb('+r+','+g+','+b+')';
}
</script>
</body>
</html>
";
}else{
echo "密码错误<br />";
echo "<a href='index.html'>返回重新登陆</a>";
}
}else{
echo "账号不存在,请注册<br />";
echo "<a href='index.html'>点击返回登陆页面</a>";
}
?>