PHP——0127加登录页面,加查询,加方法,加提示框
数据库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"/>
<span>姓名:</span>
<input type="text" name="name"/>
<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> <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="添加" /> <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="修改" /> <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加登录页面,加查询,加方法,加提示框的更多相关文章
- PHP——修改数据库2-加提示框,加登录页面
登录页面:0127lianxi.php <body> <h1>登陆</h1> <form action="0127lianxi.php" ...
- jquery中load()加载页面,刷新之后,加载的页面不显示的解决办法
<script language="javascript" type="text/javascript"> $(function(){ $(&quo ...
- jquery加载页面的方法
jquery加载页面的方法(页面加载完成就执行),建议大家看下windows.onload与$(document).ready之间的区别. 1.$(function(){ $("#a&q ...
- jquery加载页面的方法(页面加载完成就执行)
jquery加载页面的方法(页面加载完成就执行),建议大家看下windows.onload与$(document).ready之间的区别. 1.$(function(){ $("#a&qu ...
- ExtJs非Iframe框架加载页面实现
在用Ext开发App应用时,一般的框架都是左边为菜单栏,中间为tab页方式的显示区域.而tab页面大多采用的嵌入一个iframe来显示内容.但是采用iframe方式有一个很大的弊端就是每次在加载一个新 ...
- [转]jquery加载页面的方法(页面加载完成就执行)
jquery加载页面的方法(页面加载完成就执行),建议大家看下windows.onload与$(document).ready之间的区别. 1.$(function(){ $("#a&q ...
- 原生js与jquery加载页面元素比较
原生js:将获取元素的语句写到页面头部,会因为元素还没有加载而出错,js提供了window.onload 这个方法事先加载元素 <script type="text/javascrip ...
- asp.net跳转页面的三种方法比较(转)
2006-10-20 14:32 [小 大] 来源: 博客园 评论: 0分享至: 百度权重查询 词库网 网站监控 服务器监控 SEO监控 手机游戏 iPhone游戏 今天老师讲了三种跳转页面的方法,现 ...
- asp.net跳转页面的三种方法比较
目前,对于学习asp.net的很多朋友来讲,实现跳转页面的方法还不是很了解.本文将为朋友们介绍利用asp.net跳转页面的三种方法,并对其之间的形式进行比较,希望能够对朋友们有所帮助. ASP.NET ...
随机推荐
- spring mvc--默认都使用了哪些bean
在MVC中默认使用的bean都定义在了 org.springframework.web.servlet下的DispatcherServlet.properties 下载源文件后可查看到默认bean定义 ...
- 用rpm安装软件的常用步骤
假设软件叫software.rpm 1.安装前,查看是否安装过用 rpm -q software 2.安装时,用 rpm -ivh software.rpm 3.安装后想删除,用 rpm -e sof ...
- Jmeter--google plugin插件监控被測系统资源方法
一.插件准备 1.插件下载地址 http://jmeter-plugins.org/downloads/all/ 下面有两个版本号的.1.1.2和1.1.3.注意Jmeter版本号 1.1.2支持Jm ...
- nginx的 CPU參数worker_processes和worker_cpu_affinity使用说明
Nginx默认没有开启利用多核CPU,我们能够通过添加worker_cpu_affinity配置參数来充分利用多核CPU.CPU是任务处理,计算最关键的资源,CPU核越多.性能就越好. worker_ ...
- js 字符串indexof与search方法的区别
1.indexof方法 indexOf() 方法可返回某个指定的字符串值在字符串中首次出现的位置. 语法: 注意:有可选的参数(即设置开始的检索位置). 2.search方法 search() 方法用 ...
- JSP 九大隐式对象
final javax.servlet.jsp.PageContext pageContext; javax.servlet.http.HttpSession session = null; fina ...
- jquery 入门与知识
一)什么是jQuery? [以封装的思想,重构<<图片显示和隐藏>>] 第三方组织预先写好的一些实用JS文件.类,方法,都统称为JS实用库,免费放在网上,同时配有相关的学习文档 ...
- Python 调试:step into/step out/step over 的区别
Python 调试:step into/step out/step over 的区别: 首先在PyCharm 程序中设置 “ 断点 ”,后点击右上角的Debug 按钮进入调试程序状态: step in ...
- 字符编解码的故事(ASCII,GBK,Unicode,Utf-8区别)
很久很久以前,有一群人,他们决定用8个可以开合的晶体管来组合成不同的状态,以表示世界上的万物.他们认为8个开关状态作为原子单位很好,于是他们把这称为"字节". 再后来,他们又做了一 ...
- poj 3691 DNA repair(AC自己主动机+dp)
DNA repair Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5877 Accepted: 2760 Descri ...