PHP——修改数据库2-加提示框,加登录页面
2016-01-27 23:39
676 查看
<!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> <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"]."%'";//where前面必须有空格 } //else {$strsel = " where Code = '".$_POST["code"]."'";}可以省略 } else { if(@$_POST["name"]!= null) { $strsel = " where Name like '%".$_POST["name"]."%'";//where前面必须有空格 } //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>
相关文章推荐
- PHP之进制转换
- 编译php-5.5.15出错,xml2-config not found
- [总结]PHP面向对象
- Hbase启动时无法启动HRegionServer进程
- PHP实现中文名称文件下载
- PHP强制转换类型
- PHP——转义字符
- PHP学习之MySql函数·微型博客
- php中error与exception的区别及应用
- PHP小函数
- 学习Slim Framework for PHP v3 (六)--route怎么被匹配的?
- Thinkphp结合PHPMailer发邮件
- ubuntu14.04 server ftp 服务安装配置详解
- ubuntu14.04 server ftp 服务安装配置详解
- 0--PHP初识之路
- 本人开发中的一些笔记(三)--- 个人一些比较少用的php函数
- php页面静态化
- PHP修改session的生存期
- CI框架 -- CLI执行php代码
- 学习Slim Framework for PHP v3 (五)--route怎么被调用的?