这个是学PHP时写的一个简单的php同学录作业,用的DW和wamp使用sqli连接数据库,比较简单没有写登录界面(需要的可自行编写)。
1.欢迎界面

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title><style>body{background-image: url("image/view1.jpg");background-size: cover;background-repeat: no-repeat;margin-top: 250px;text-align: center;font-size: 40px;font-family:STXingkai;}div{margin-top: 10px;}button{background-color: transparent;font-size: 40px;font-family:STXingkai;}</style><script>function insert(){window.location="view.php";}function search(){window.location="search.php";}function deleteview(){window.location="deleteview";}function edit(){window.location="updateview";}</script>
</head><body><h3>欢迎来到18软工的留言板</h3><button type="button" onClick="insert()">添加留言</button><button name="search" onClick="search()">查看留言</button><div class="change"><button name="delete" onClick="deleteview()">删除留言</button><button name="edit" onClick="edit()">修改留言</button></div></body>
</html>

2.添加留言的用户界面和数据库操作语句

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title><style>body{background-image:url("image/background.jpg");background-size: cover;background-repeat: no-repeat;font-size: 40px;font-family:STXingkai;}center{margin-top: 200px;}input{background-color: transparent;border-left-width:0px;border-right-width: 0px;border-top-width: 0px;font-size: 30px;font-family:STXingkai;}       textarea{background-color: transparent;border-left-width:0px;border-right-width: 0px;border-top-width: 0px;border-bottom-width: 0px;font-size: 30px;font-family:STXingkai;}button{background-color: transparent;font-size: 40px;font-family:STXingkai;}</style>
</head><body><center><h3>添加留言</h3><form action = "insert.php" method = "post"><table width = "auto" border = "0" cellpadding = "4"><tr><td  align = "right">标题:</td><td><input type = "text" name = "title" ></td></tr><tr><td  align = "right">留言者:</td><td><input type ="text" name = "name"></td></tr><tr><td align = "right" valign = "top">留言内容:</td><td><textarea name = "content" row = "5" cols = "30"></textarea></td></tr><tr><td align = "right" valign = "top">联系电话:</td><td><input type = "number" name = "phone"></td></tr><tr><td align = "right" valign = "top">联系邮箱:</td><td><input type ="text" name = "email"></td></tr><tr><td align = "right" valign = "top">QQ:</td><td><input type = "number" name = "qqnumber"></td></tr><tr><td colspan = "2" align = "center"><button type="submit">提交</button><button type="reset">重置</button></td></tr></table></form>
</center>
</body>
</html>
<?php //连接数据库$db=mysqli_connect("localhost","root","")or die("连接失败");mysqli_select_db($db,"lyb");mysqli_query($db,"set names utf8");//获取数据$title=$_POST["title"];$name=$_POST["name"];$content=$_POST["content"];if(!is_numeric($_POST["phone"])){echo "请输入正确的电话号码";}elseif(strlen($_POST["phone"])!=11){echo "请输入正确的号码";}else{$phone=$_POST["phone"];}$email=$_POST["email"];$qqnumber=$_POST["qqnumber"];//插入数据$sql="insert into software value('$title','$name','$content',$phone,'$email',$qqnumber)";$result=mysqli_query($db,$sql);if(!$result){printf("Error: %s", mysqli_error($db));}else{echo "成功两秒后跳转";header("refresh:2;url=login.php");mysqli_close($db);}?>

3.查询内容的用户界面和对应的数据库操作语句

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title><style>body{background-image:url("image/background.jpg");background-size: cover;background-repeat: no-repeat;margin-top: 250px;font-size: 35px;font-family:STXingkai;}input{background-color: transparent;border-left-width:0px;border-right-width: 0px;border-top-width: 0px;font-size: 40px;font-family:STXingkai;}button{float: right;background-color: transparent;font-size: 35px;font-family:STXingkai;}          </style><script>function returnview(){window.location="login.php";}</script>
</head><body><center><h3>我的留言板</h3><?php$db=mysqli_connect("localhost","root","");mysqli_select_db($db,"lyb");mysqli_query($db,"set names utf8");$sql="select * from software";$result=mysqli_query($db,$sql);echo "<table border=2 >";echo "<tr><th>标题</th><th>姓名</th><th>内容</th><th>电话</th><th>邮箱</th><th>QQ</th></tr>\n";while ($myrow=mysqli_fetch_row($result)){printf("<tr> <td>%s</td> <td>%s</td><td>%s</td><td>%s</td> <td>%s</td> <td>%s</td> </tr>", $myrow[0], $myrow[1], $myrow[2], $myrow[3],$myrow[4],$myrow[5]);}echo "</table>";mysqli_close($db);?></center><button type="submit" onClick="returnview()">返回</button>
</body>
</html>

4.删除的用户界面和对应的数据库操作语句

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title><style>body{background-image:url("image/background.jpg");background-size: cover;background-repeat: no-repeat;margin-top: 300px;font-size: 40px;font-family:STXingkai;}input{background-color: transparent;border-left-width:0px;border-right-width: 0px;border-top-width: 0px;font-size: 40px;font-family:STXingkai;}button{background-color: transparent;font-size: 40px;font-family:STXingkai;}</style>
</head><body><center><!删除留言板--><h3>删除留言板</h3><form action="delete.php" method="post"><tr>             <td  align="right">输入留言者姓名:</td><td><input type="text" name ="name"></td></tr><button type="submit">确定</button></form></center>
</body>
</html>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title><style>body{font-size: 40px;font-family:STXingkai;}</style>
</head><body><?php$db=mysqli_connect("localhost","root","");mysqli_select_db($db,"lyb");mysqli_query($db,"set names utf8");$name=$_POST['name'];$sql="delete from software where name='$name'";$result=mysqli_query($db,$sql);if(!$result){echo mysql_error();exit();   }else{  echo "删除成功2秒后跳转";header("refresh:2;url=login.php");mysqli_close($db);}?>
</body>
</html>

5.修改留言的用户界面和对应的数据库操纵语句

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title><style>body{background-image:url("image/background.jpg");background-size: cover;background-repeat: no-repeat;margin-top: 300px;font-size: 40px;font-family:STXingkai;}input{background-color: transparent;border-left-width:0px;border-right-width: 0px;border-top-width: 0px;font-size: 40px;font-family:STXingkai;}button{background-color: transparent;font-size: 40px;font-family:STXingkai;}</style>
</head>
<body><center><!修改留言板--><h3>修改留言板</h3><form action="edit.php" method="post"><tr>                <td  align="right">输入留言者姓名:</td><td><input type="text" name ="name"></td></tr><button type="submit">确定</button></form></center>
</body>
</html>
<!doctype html>
<html>
<head>
<meta  charset="utf-8">
<title>无标题文档</title><style>body{background-image:url("image/background.jpg");background-size: cover;background-repeat: no-repeat;font-size: 40px;font-family:STXingkai;}center{margin-top: 200px;}input{background-color: transparent;border-left-width:0px;border-right-width: 0px;border-top-width: 0px;font-size: 30px;font-family:STXingkai;}       textarea{background-color: transparent;border-left-width:0px;border-right-width: 0px;border-top-width: 0px;border-bottom-width: 0px;font-size: 30px;font-family:STXingkai;}button{background-color: transparent;font-size: 40px;font-family:STXingkai;}</style>
</head><body><center><h2>修改留言板</h2><?php$db=mysqli_connect("localhost","root","");mysqli_select_db($db,"lyb");mysqli_query($db,"set names utf8");$name=$_POST['name'];$sql="select * from software where name='$name'";$res=mysqli_query($db,$sql);$arr=mysqli_fetch_assoc($res);?><form action = "update.php" method = "post"><table width = "auto" border = "0" cellpadding = "4"><tr><td  align = "right">标题:</td><td><input type = "text" name = "title" value="<?php echo $arr['title'] ?>" /></td></tr><tr><td  align = "right">留言者:</td><td><input type = "text" name = "name" value="<?php echo $arr['name'] ?>"/></td></tr><tr><td align = "right" valign = "top">留言内容:</td><td><textarea name = "content" row = "5" cols = "30" ><?php echo $arr['content'] ?></textarea></td></tr><tr><td align = "right" valign = "top">联系电话:</td><td><input type = "number" name = "phone" value="<?php echo $arr['phone'] ?>"/></td></tr><tr><td align = "right" valign = "top">联系邮箱:</td><td><input type = "text" name = "email" value="<?php echo $arr['email'] ?>"/></td></tr><tr><td align = "right" valign = "top">QQ:</td><td><input type = "number" name = "qqnumber" value="<?php echo $arr['qqnumber'] ?>"/></td></tr><tr><td colspan = "2" align = "center"><button type="submit">修改留言</button><button type="reset">重置</button></td></tr></table></form></center>
</body>
</html>
<!doctype html>
<html>
<head>
<meta  charset="utf-8">
<title>无标题文档</title><style>body{font-size: 40px;font-family:STXingkai;}</style>
</head><body><?php$db=mysqli_connect("localhost","root","");mysqli_select_db($db,"lyb");mysqli_query($db,"set names utf8");//获取数据$title=$_POST["title"];$name=$_POST["name"];$content=$_POST["content"];if(!is_numeric($_POST["phone"])){echo "请输入正确的电话号码";}elseif(strlen($_POST["phone"])!=11){echo "请输入正确的号码";}else{$phone=$_POST["phone"];}$email=$_POST["email"];$qqnumber=$_POST["qqnumber"];//更新数据库数据$sql="update software set title='$title',name='$name',content='$content',phone=$phone,email='$email',qqnumber=$qqnumber where name='$name'";$result=mysqli_query($db,$sql);if(!$result){printf("Error: %s", mysqli_error($db));}else{echo "成功两秒后跳转";header("refresh:2;url=login.php");mysqli_close($db);}?>
</body>
</html>

效果图:


个别界面含有隐私内容这里就不贴出来了,下面是编写留言板时使用的数据库大家可自行下载:

链接:https://pan.baidu.com/s/11wNtBj2PhHyZPlkurcTF7g
提取码:usz3

总结:
总的来说php语言是较简单的计算机语言,在连接数据库方面也是很直接的连接方式。需要注意的是在较新版本的php当中连接数据库以及操作数据库用的较多的是sqli语句该语句与旧版的语句是存在不同的。

PHP简单同学录(连接数据库)相关推荐

  1. 简单的连接数据库的Web登录界面

    简单的连接数据库的Web登录界面 一.需求分析 实现在登录界面输入用户名和密码,连接数据库,与数据库信息进行比对,若用户名和密码相互匹配,则显示登陆成功,若不正确,选择重新输入. 二.工具 1.MyS ...

  2. 用ajax连接mysql_页面用ajax实现简单的连接数据库

    (1) 写发送代码 var myXmlHttpRequest = ""; myXmlHttpRequest = getXmlHttpRequest(); if (myXmlHttp ...

  3. 页面用ajax实现简单的连接数据库

    (1) 写发送代码 var myXmlHttpRequest = ""; myXmlHttpRequest = getXmlHttpRequest();             i ...

  4. 简单的php连接数据库代码,php连接数据库标准代码

    摘要 腾兴网为您分享:php连接数据库标准代码,智宽生活,掌上看家,优酷,网易uu等软件知识,以及修改地址软件,金鲨银鲨,excelwps,关键词采集软件,斗鱼企鹅送鱼丸,车牌,亿童网站,考拉翻译,智 ...

  5. php输出mysql查询结果_PHP简单获取数据库查询结果并返回JSON

    header("Content-type:text/html;charset=utf-8"); //连接数据库 $con = mysql_connect("localho ...

  6. 【java连接数据库】idea、MySQL5.7和SQLyog工具

    要求:java连接MySQL数据库,可替换成其他数据库,版本也不一定要和这里完全相同,我只是把我用到的贴上来.不管用什么版本和软件,连接成功即可. 所用到的软件和工具如下: 1.idea2021.1. ...

  7. Metasploit数据库连接及其简单应用

    Metasploit数据库连接及其简单应用 连接数据库 1 第一步开启数据库服务 2 第二步查看数据库状态-----有没有启动(看红色部分) 3 第三步切换用户 4 第四步创建用户 注释:xiangc ...

  8. Sequel pro 简单使用

    Sequel pro 简单使用 连接数据库 # 窗口功能 添加表 添加项目 sequel pro 只能执行一行sql指令 连接数据库 name其实无所谓 把主机号填上,如果是本机填127.0.0.1 ...

  9. cygwin中写c语言程序,在windows下怎么利用Cygwin进行编程

    Windows下使用C语言+嵌入SQL实现DB2开发 Cygwin,gcc的介绍和安装在前面的文章有将过,请参考 在Windows中使用Cygwin环境下的gcc编译器编译Informix ESQ/C ...

  10. Linux入门最终集! Vue SpringBoot Mybatis-Plus Linux 阿里云!

    Linux入门最终集! Vue & SpringBoot & Mybatis-Plus & Linux & 阿里云! 一.Xshell连接时出现警告 The remot ...

最新文章

  1. 1小时学会:最简单的iOS直播推流(五)yuv、pcm数据的介绍和获取
  2. sql server的BCP导入导出(转)
  3. mysql查找执行效率慢的SQL语句
  4. mysql必知必会学习笔记(一)
  5. asp.net core源码飘香:Logging组件
  6. 计算机常用英语1000个,1000个常用英语单词.pdf
  7. 关于C#日期格式化问题
  8. 将 Typora 小工具添加到右键菜单中
  9. android获取运行应用程序,Android中获取正在运行的应用程序
  10. 9. 大型网站架构模式
  11. LeetCode:每日一题(2020.4.7)
  12. 从零开始搭二维激光SLAM --- Karto的前端实现与解读
  13. error LNK2005: 已经在 app_launcher.obj 中定义
  14. BLUE引擎检查放入装备的名称全名脚本
  15. _ZN10tensorflow8internal21CheckOpMessageBuilder9NewStringEv
  16. 制作可被svchost调用的服务(下)
  17. 128-Vue中的事件修饰符-阻止冒泡事件
  18. 几何向量:空间三角形外心和法向量
  19. JavaScript 基础1入门、变量、运算符、表达式、进制
  20. 吃鸡哪个服务器网络稳定,中国地区吃鸡哪个服务器不卡 | 手游网游页游攻略大全...

热门文章

  1. 视觉中国,董事长是加拿大籍,总裁是美国籍
  2. 像素坐标转换实际坐标python_像素坐标转世界坐标的计算
  3. 计算机考研作息时间表,985学长强力推荐考研作息时间表!
  4. mysql不等于多个数怎么写_mysql不等于符号怎么写
  5. vue2使用 relation-graph 展示关系图谱
  6. ppt模板怎样用到html中,PPT模板怎么设置(ppt模板怎么竖版)
  7. PID控制电机输出作为电机PWM占空比输入的理解
  8. matlab 线性拟合polyfit_Matlab实现线性回归(直线拟合)
  9. 广义逆矩阵:加号逆(A+)与减号逆(A-)
  10. 8086微处理器介绍