PHP连接数据库实现页面增删改查效果

2022-04-17 14:45:55
目录
效果图实现代码sqlcyg.phpdelete.phpupdate.phpcreate.php

效果图

_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

cyg.php

<?php$link=mysqli_connect('localhost','root','','a');//然后是指定php链接数据库的字符集mysqli_set_charset($link,'utf8');$sql="select * from search";//模糊查询出像数据库中的title或者content里面的值或者说像数据库中的title或者content里面的某一段值相对应的就行了,就可以输出啦$result=mysqli_query($link,$sql);//运行sql?><!--显示的效果--><!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Document</title></head><body><tablfWKxpe border="1" cellpadding="5"><tr><td>id</td><td>标题</td><td>内容</td><?php while ($row=mysqli_fetch_array($result)) {//把对象编程数组输出,不然会报错哦# code...?><tr><td><?=$row['id'];?></td><td><?=$row['content'];?></td><td><a href="update.php?id=<?php echo $row['id']; ?>" rel="external nofollow" >更新</a></td><td><a href="delete.php?id=<http://www.easck.com;?php echo $row['id']; ?>" rel="external nofollow" >删除</a></td><td><a href="create.php" rel="external nofollow"  rel="external nofollow"  rel="external nofollow" >创建</a></td></tr><?php }?></tr></table></body></html>

delete.php

<?php$link=mysqli_connect('localhost','root','','a');//然后是指定php链接数据库的字符集mysqli_set_charset($link,'utf8');//$sql = "DELETE FROM `search` WHERE `id` = '$_POST[id]'";//模糊查询出像数据库中的title或者content里面的值或者说像数据库中的title或者content里面的某一段值相对应的就行了,就可以输出啦$result=mysqli_query($link,"DELETE FROM search WHERE id ='$_GET[id]'");//运行sql$sql="select * from search";//模糊查询出像数据库中的title或者content里面的值或者说像数据库中的title或者content里面的某一段值相对应的就行了,就可以输出啦$result=mysqli_query($link,$sql);//运行sql?><!--显示的效果--><!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Document</title></head><body><table border="1" cellpadding="5"><tr><td>id</td><td>标题</td><td>内容</td><?php while ($row=mysqli_fetch_array($result)) {//把对象编程数组输出,不然会报错哦# code...?><tr><td><?=$row['id'];?></td><td><?=$row['content'];?></td><td><a href="update.php?id=<?= $row['id']; ?>" rel="external nofollow"  rel="external nofollow" >更新</a></td><td><a href="delete.php?id=<?= $row['id']; ?>" rel="external nofollow"  rel="external nofollow" >删除</a></td><td><a href="create.php" rel="external nofollow"  rel="external nofollow"  rel="external nofollow" >创建</a></td></tr><?php }?></tr></table></body></html>

update.php

<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Document</title></head><body><form action="update.php" method="GET"><input type="hidden" name="id" value="<?php echo $_GET['id']?>"><input type="text" name="content"><input type="submit" value="搜索"></form></body></html><?php$link=mysqli_connect('localhost','root','','a');//然后是指定php链接数据库的字符集mysqli_set_charset($link,'utf8');//$sql = "DELETE FROM `search` WHERE `id` = '$_POST[id]'";//模糊查询出像数据库中的title或者content里面的值或者说像数据库中的title或者content里面的某一段值相对应的就行了,就可以输出啦$result=mysqli_query($link,"UPDATE search set content='$_GET[content]' WHERE id ='$_GET[id]'");//运行sql$sql="select * from search";//模糊查询出像数据库中的title或者content里面的值或者说像数据库中的title或者content里面的某一段值相对应的就行了,就可以输出啦$result=mysqli_query($link,$sql);//运行sql?><!--显示的效果--><!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Document</title></head><body><table border="1" cellpadding="5"><tr><td>id</td><td>标题</td><td>内容</td><?php while ($row=mysqli_fetch_array($result)) {//把对象编程数组输出,不然会报错哦# code...?><tr><td><?=$row['id'];?></td><td><?=$row['content'];?></td><td><a href="update.php?id=<?= $row['id']; ?>" rel="external nofollow"  rel="external nofollow" >更新</a></td><td><a href="delete.php?id=<?= $row['id']; ?>" rel="external nofollow"  rel="external nofollow" >删除</a></td><td><a href="create.php" rel="external nofollow"  rel="external nofollow"  rel="external nofollow" >创建</a></td></tr><?php }?></tr></table></body></html>

create.php

<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Document</title></head><body><form action="create.php" method="POST"><input type="text" name="content"><input type="submit" value="提交"></form></body></html><?phpif(!$_POST['content']){exit();}$content=$_POST['content'];$link=mysqli_connect('localhost','root','','a');//然后是指定php链接数据库的字符集mysqli_set_charset($link,'utf8');$sql = "INSERT INTO search(content)VALUES ('{$content}')"; $result=mysqli_query($link,$sql);echo "<script>alert('创建成功');</script>";?>

以上就是PHP连接数据库实现页面增删改查效果的详细内容,更多关于PHP增删改查的资料请关注我们其它相关文章!

相关文章 大家在看