数据库mydb

表格info,nation,login

效果

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head> <body>
<h1>登陆</h1>
<form action="0127lianxi.php" method="post">
<div> <span>用户名:</span><input type="text" name="uid" /></div>
<div> <span>密 码:</span><input type="text" name="pwd" /></div>
<div><input type="submit" name="btn" value="登录" /></div>
</form>
</body>
</html>

0127denglu.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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head> <body>
<h1>主页面</h1>
<form action="0127lianxi.php" method="post">
<div style="width:100%; height:40px">
<span>代号:</span>
<input type="text" name="code"/> &nbsp;&nbsp;
<span>姓名:</span>
<input type="text" name="name"/>&nbsp;&nbsp;
<input type="submit" value="查询" name="btn"/>
</div>
</form> <div>
<?php //登录代码
/*include("0127mydbda.php"); $uid=$_POST["uid"];
$pwd=$_POST["pwd"]; $dl = new mydbda(); $sqldl = "select * from login where UserName='{$uid}' and Password='{$pwd}'"; $jieguo = $dl->select($sqldl,"CX","mydb");
if($jieguo=="")
{
header("Location:0127denglu.php");
}
else
{
}*/ /*if($rowdl=$jieguo->fetch_row())//与后面的return $result对应
{
}
else
{
header("Location:0127denglu.php");
}*/ /*if($dl->denglu($uid,$pwd)=="ok")//通过上面方法优化
{
}
else
{
header("Location:0127denglu.php");
}*/ //查询代码 $strsel = ""; if(@$_POST["code"] != null)
{
$strsel = " where Code = '".$_POST["code"]."'";//where前面必须有空格 if(@$_POST["name"]!= null)
{
$strsel = " where Code='".$_POST["code"]."' and Name like '%".$_POST["name"]."%'";
}
//else {$strsel = " where Code = '".$_POST["code"]."'";}可以省略
}
else
{
if(@$_POST["name"]!= null)
{
$strsel = " where Name like '%".$_POST["name"]."%'";
}
//else{$strsel="";}都为空执行最开始的$strsel
} //1.连接数据可以
$db = new mysqli("localhost","root","123","mydb");
//2.判断是否连接成功
if(mysqli_connect_error())
{
echo "连接失败";
}
else
{
//3.写sql语句
$sql = "select * from Info".$strsel;
//4.执行sql语句
$result=$db->query($sql);
//5.处理数据,遍历数据 echo "<table width=90% cellpadding=0 cellspacing=0 border=1>";
echo "<tr> <td>代号</td> <td>姓名</td> <td>性别</td> <td>民族</td> <td>生日</td> <td>操作</td> </tr>";
while($row=$result->fetch_row())
{
//改性别
$sex=$row[2]?"男":"女";
//改民族
$nation=NationName($db,$row[3]);
//改生日
$birthday=date("Y年m月d日",strtotime($row[4])); echo "<tr bgcolor='#00FFCC'> <td>{$row[0]}</td> <td>{$row[1]}</td> <td>{$sex}</td> <td>{$nation}</td> <td>{$birthday}</td> <td><a href='0127sc.php?code=".$row[0]."' onclick=\"return confirm('确定删除吗?')\">删除</a>&nbsp;&nbsp;<a href='0127xiugai.php?code=".$row[0]."'>修改</a></td> </tr>";//\" \"双引号里出现双引号转义字符用 }
echo "</table>";
} function NationName($db,$code)
{
//写sql语句
$sql="select * from nation where code='{$code}'";
//4.执行sql语句
$result=$db->query($sql);
//5.处理数据
if($row=$result->fetch_row())
{
return $row[1];
}
else
{
return "";
} } ?>
</div>
<div><a href="0127tianjia.php">添加数据</a></div>
<form>
<input type="submit" value="提交" onclick="return confirm('确定么')" />
</form>
</body>
</html>

0127lianxi.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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head> <body>
<?php
class mydbda
{
var $host="localhost";
var $username="root";
var $password="123";
var $database="mydb"; /*
功能:执行SQL语句,返回结果
参数:$sql:要执行的SQL语句
$type:SQL语句的类型,CX代表查询,QT代表其他
$data:要操作的数据库
返回值:如果是查询,返回结果集
如果是其他语句,执行成功返回ok,失败返回no
*/ function select($sql,$type,$data)
{ $db=new mysqli($this->host,$this->username,$this->password,$data);
if(mysqli_connect_error())
{
echo "连接失败";
exit;
}
else
{
$result=$db->query($sql);
if($type=="CX")
{
//return $result; 用拼接字符串替换掉
$str="";
while($row=$result->fetch_row())
{
for($i=0;$i<count($row);$i++)
{
$str=$str.$row[$i]."^"; }
$str=substr($str,0,strlen($str)-1);//去掉"|"前面的"^" $str = $str."|";
//n001^汉族^|n002^回族^|n003^苗族^|
}
$str=substr($str,0,strlen($str)-1);//去掉"|"
return $str; }
else
{
if($result)
{
return "ok";
}
else
{
return "no";
}
} }
} /*function denglu($uid,$pwd)
{
$db=new mysqli($this->host,$this->username,$this->password,$this->database);
if(mysqli_connect_error())
{
echo "连接失败";
exit;
}
else
{
$sql="select * from login where UserName='{$uid}' and Password='{$pwd}'" ;
$result=$db->query($sql);
if($row=$result->fetch_row())
{
return "ok";
}
else
{
return "no";
} } }*/ } ?>
</body>
</html>

0127mydb.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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head> <body>
<h1>添加页面</h1>
<form action="0127tjchuli.php" method="post">
<div><span>代号:</span><input type="text" name="code" /></div>
<div><span>姓名:</span><input type="text" name="name" /></div>
<div><span>性别:</span><input type="radio" checked="checked" name="sex" value="true"/>男
<input type="radio" name="sex" value="false"/>女
</div>
<div>
<span>民族:</span>
<select name="nation">
<?php
$db=new mysqli("localhost","root","123","mydb");
if(mysqli_connect_error())
{
echo "连接错误";
}
else
{
$sql="select * from nation";
$result=$db->query($sql);
while($row=$result->fetch_row())
{
echo "<option value='{$row[0]}'>{$row[1]}</option>";
} } ?>
</select> </div>
<div><span>生日:</span><input type="text" name="birthday"/></div>
<div><input type="submit" value="添加" />&nbsp;&nbsp;<a href="0127lianxi.php">返回</a></div>
</form>
</body>
</html>

0127tianjia.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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head> <body>
<?php
$code=$_GET["code"];
$db=new mysqli("localhost","root","123","mydb");
if(mysqli_connect_error())
{
echo "连接错误";
}
else
{
$sql="delete from Info Where code='{$code}'";
$result=$db->query($sql);
if($result)
{
header("Location:0127lianxi.php");
}
else
{
echo "删除失败";
} } ?>
</body>
</html>

0127sc.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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head> <body>
<h1>修改页面</h1>
<?php
$code=$_GET["code"];
$db=new mysqli("localhost","root","123","mydb");
if(mysqli_connect_error())
{
echo "连接错误";
}
else
{
$sql="select * from Info where code='".$code."'";
$result=$db->query($sql);
$row=$result->fetch_row();
} ?>
<form action="0127xgchuli.php" method="post">
<div><span>代号:</span><input type="text" name="code" value="<?php echo $row[0] ?>" readonly="readonly"/></div>
<div><span>姓名:</span><input type="text" name="name" value="<?php echo $row[1] ?>" /></div>
<div><span>性别:</span><input type="radio" <?php echo (bool)$row[2]?"checked='checked'":"" ?> name="sex" value="true"/>男
<input type="radio" name="sex" value="false" <?php echo !(bool)$row[2]?"checked='checked'":"" ?>/>女
</div>
<div>
<span>民族:</span>
<select name="nation">
<?php
$db=new mysqli("localhost","root","123","mydb");
if(mysqli_connect_error())
{
echo "连接错误";
}
else
{
$sql="select * from nation";
$result=$db->query($sql);
while($rownation=$result->fetch_row())
{
if($rownation[0]==$row[3])
{
echo "<option selected='selected' value='{$rownation[0]}' >{$rownation[1]}</option>";
}
else
{
echo "<option value='{$rownation[0]}'>{$rownation[1]}</option>";
}
} } ?>
</select> </div>
<div><span>生日:</span><input type="text" name="birthday" value="<?php echo $row[4] ?>"/></div>
<div><input type="submit" value="修改" />&nbsp;&nbsp;<a href="0127lianxi.php">返回</a></div>
</form>
</body>
</html>

0127xiugai.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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head> <body>
<?php
$code=$_POST["code"];
$name=$_POST["name"];
$sex=$_POST["sex"];
$nation=$_POST["nation"];
$birthday=$_POST["birthday"];
//1.造连接对象
$db=new mysqli("localhost","root","123","mydb");
//2.判断是否连接成功
if(mysqli_connect_error())
{
echo "连接失败";
}
else
{
//3.写语句
$sql="update info set name='".$name."',sex='".$sex."',nation='".$nation."',birthday='".$birthday."'where code='".$code."'";
//4.执行sql语句
$result = $db->query($sql);
//判断是否修改成功
if($result)
{
header("Location:0127lianxi.php");
}
else
{
echo "修改失败!";
} } ?>
</body>
</html>

0127xgchuli.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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head> <body>
<?php
$code=$_POST["code"];
$name=$_POST["name"];
$sex=$_POST["sex"];
$nation=$_POST["nation"];
$birthday=$_POST["birthday"]; $db=new mysqli("localhost","root","123","mydb");
if(mysqli_connect_error())
{
echo "连接错误";
}
else
{
$sql="insert into Info values('{$code}','{$name}',{$sex},'{$nation}','{$birthday}')";
$result=$db->query($sql);
if($result)
{
header("Location:0127tianjia.php");
}
else
{
echo "添加失败";
}
} ?>
</body>
</html>

0127tjchuli.php

0127tjchuli.php中的$sex写法要注意bit和varchar的变量写法

PHP——0127加登录页面,加查询,加方法,加提示框的更多相关文章

  1. PHP——修改数据库2-加提示框,加登录页面

    登录页面:0127lianxi.php <body> <h1>登陆</h1> <form action="0127lianxi.php" ...

  2. jquery中load()加载页面,刷新之后,加载的页面不显示的解决办法

    <script language="javascript" type="text/javascript"> $(function(){ $(&quo ...

  3. jquery加载页面的方法

    jquery加载页面的方法(页面加载完成就执行),建议大家看下windows.onload与$(document).ready之间的区别.   1.$(function(){ $("#a&q ...

  4. jquery加载页面的方法(页面加载完成就执行)

    jquery加载页面的方法(页面加载完成就执行),建议大家看下windows.onload与$(document).ready之间的区别. 1.$(function(){  $("#a&qu ...

  5. ExtJs非Iframe框架加载页面实现

    在用Ext开发App应用时,一般的框架都是左边为菜单栏,中间为tab页方式的显示区域.而tab页面大多采用的嵌入一个iframe来显示内容.但是采用iframe方式有一个很大的弊端就是每次在加载一个新 ...

  6. [转]jquery加载页面的方法(页面加载完成就执行)

    jquery加载页面的方法(页面加载完成就执行),建议大家看下windows.onload与$(document).ready之间的区别.   1.$(function(){ $("#a&q ...

  7. 原生js与jquery加载页面元素比较

    原生js:将获取元素的语句写到页面头部,会因为元素还没有加载而出错,js提供了window.onload 这个方法事先加载元素 <script type="text/javascrip ...

  8. asp.net跳转页面的三种方法比较(转)

    2006-10-20 14:32 [小 大] 来源: 博客园 评论: 0分享至: 百度权重查询 词库网 网站监控 服务器监控 SEO监控 手机游戏 iPhone游戏 今天老师讲了三种跳转页面的方法,现 ...

  9. asp.net跳转页面的三种方法比较

    目前,对于学习asp.net的很多朋友来讲,实现跳转页面的方法还不是很了解.本文将为朋友们介绍利用asp.net跳转页面的三种方法,并对其之间的形式进行比较,希望能够对朋友们有所帮助. ASP.NET ...

随机推荐

  1. DOS命令:列出某目录下的所有文本文件名并重定向到某文件

    命令如下: >dir /b *.txt>output.txt dir无需说,/b 是只要文件名,>是重定向. 2013年11月7日13:36:57

  2. angularjs中的interval定时执行功能

    一个例子,用来显示当前实时时间,1秒钟刷新一次: <!DOCTYPE html> <html ng-app="myApp"> <head> &l ...

  3. WCF 之 已知类型(KnownType)

    已知类型(Known types)允许在服务契约中使用多态的行为,在服务操作中暴露基本类型.将已知类型(known types)相关到基本类型(基类类型)自身;特定操作;整个服务契约采用属性声明或者配 ...

  4. taro 打包微信小程序运行失败(二)

    1.报错信息 thirdScriptError sdk uncaught third Error Cannot read property 'dispatch' of null TypeError: ...

  5. ReadOnly field saved with NULL value

    On CRM opportunity form view, i added readonly="1" for probability field. When i saved, wh ...

  6. 〖QT编程〗在Qt编程中使用/显示中文编码

    在main.cpp中添加: #include "QTextCodec" QTextCodec *codec = QTextCodec::codecForName("Sys ...

  7. SQL数据库异地备份

    服务器:windows sever 2008(简称为A) 数据库:SQL server 2008 R2(安装在A上) 普通台式机:windows 7(简称为B) 目的:将A中的数据定时自动备份到B中 ...

  8. Ubuntu8.04系列-系统优化篇

    文章欢迎转载,转载请注明出处:嘉骏苑http://luckiss.blogcn.com  原文出处:http://luckiss.blogcn.com/diary,15151058.shtml    ...

  9. spring3.1之前的HandlerMapping ,HandlerAdapter以及spring3.1写法

    <!--Spring3.1之前的注解 HandlerMapping --><!-- <bean class="org.springframework.web.serv ...

  10. 浏览器HTTP请求分析

    普通网民打开网页,访问网站,并不需要了解所谓HTTP协议.作为软件工程师,了解一下浏览器的工作过程还是一件比较有意思的事情.我向大家介绍一下当我们在浏览器的地址栏里面回车的时候,浏览器如何和Web服务 ...