最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

PHP連接數(shù)據(jù)庫實現(xiàn)頁面增刪改查效果

 更新時間:2022年03月17日 10:41:37   作者:貴哥的編程之路(熱愛分享)  
這篇文章主要介紹了如何利用PHP實現(xiàn)連接SQL數(shù)據(jù)庫,從而對頁面進行增刪改查功能,文中的示例代碼講解詳細(xì),感興趣的可以了解一下

效果圖

實現(xiàn)代碼

sql

-- phpMyAdmin SQL Dump
-- version 4.5.1
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: 2022-03-15 17:51:32
-- 服務(wù)器版本: 10.1.13-MariaDB
-- PHP Version: 5.6.21

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `a`
--

-- --------------------------------------------------------

--
-- 表的結(jié)構(gòu) `search`
--

CREATE TABLE `search` (
  `id` int(11) NOT NULL,
  `content` text COLLATE utf8_vietnamese_ci NOT NULL COMMENT '內(nèi)容'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_vietnamese_ci;

--
-- 轉(zhuǎn)存表中的數(shù)據(jù) `search`
--

INSERT INTO `search` (`id`, `content`) VALUES
(21, '陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴'),
(22, '陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴'),
(23, '陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴'),
(24, '陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴'),
(25, '陳作業(yè)貴'),
(26, '陳作業(yè)貴'),
(27, '陳作業(yè)貴'),
(28, '陳作業(yè)貴'),
(29, '000000'),
(30, '');

--
-- Indexes for dumped tables
--

--
-- Indexes for table `search`
--
ALTER TABLE `search`
  ADD PRIMARY KEY (`id`);

--
-- 在導(dǎo)出的表使用AUTO_INCREMENT
--

--
-- 使用表AUTO_INCREMENT `search`
--
ALTER TABLE `search`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=67;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

cyg.php

<?php
$link=mysqli_connect('localhost','root','','a');
//然后是指定php鏈接數(shù)據(jù)庫的字符集
mysqli_set_charset($link,'utf8');
$sql="select * from search";
//模糊查詢出像數(shù)據(jù)庫中的title或者content里面的值或者說像數(shù)據(jù)庫中的title或者content里面的某一段值相對應(yīng)的就行了,就可以輸出啦
$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>標(biāo)題</td>
			<td>內(nèi)容</td>
		
		<?php 
			while ($row=mysqli_fetch_array($result)) {//把對象編程數(shù)組輸出,不然會報錯哦
				# 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=<?php echo $row['id']; ?>" rel="external nofollow" >刪除</a></td>
			<td><a href="create.php" rel="external nofollow"  rel="external nofollow"  rel="external nofollow" >創(chuàng)建</a></td>
		</tr>
		<?php 
		}
		?>
		</tr>
	</table>
</body>
</html>

delete.php

<?php
$link=mysqli_connect('localhost','root','','a');
//然后是指定php鏈接數(shù)據(jù)庫的字符集
mysqli_set_charset($link,'utf8');
//$sql = "DELETE FROM `search` WHERE `id` = '$_POST[id]'";

//模糊查詢出像數(shù)據(jù)庫中的title或者content里面的值或者說像數(shù)據(jù)庫中的title或者content里面的某一段值相對應(yīng)的就行了,就可以輸出啦
$result=mysqli_query($link,"DELETE FROM search WHERE id ='$_GET[id]'");//運行sql
$sql="select * from search";
//模糊查詢出像數(shù)據(jù)庫中的title或者content里面的值或者說像數(shù)據(jù)庫中的title或者content里面的某一段值相對應(yīng)的就行了,就可以輸出啦
$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>標(biāo)題</td>
			<td>內(nèi)容</td>
		
		<?php 
			while ($row=mysqli_fetch_array($result)) {//把對象編程數(shù)組輸出,不然會報錯哦
				# 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" >創(chuàng)建</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鏈接數(shù)據(jù)庫的字符集
mysqli_set_charset($link,'utf8');
//$sql = "DELETE FROM `search` WHERE `id` = '$_POST[id]'";

//模糊查詢出像數(shù)據(jù)庫中的title或者content里面的值或者說像數(shù)據(jù)庫中的title或者content里面的某一段值相對應(yīng)的就行了,就可以輸出啦
$result=mysqli_query($link,"UPDATE search set content='$_GET[content]' WHERE id ='$_GET[id]'");//運行sql
$sql="select * from search";
//模糊查詢出像數(shù)據(jù)庫中的title或者content里面的值或者說像數(shù)據(jù)庫中的title或者content里面的某一段值相對應(yīng)的就行了,就可以輸出啦
$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>標(biāo)題</td>
			<td>內(nèi)容</td>
		
		<?php 
			while ($row=mysqli_fetch_array($result)) {//把對象編程數(shù)組輸出,不然會報錯哦
				# 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" >創(chuàng)建</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>
<?php
if(!$_POST['content'])
{
exit();
}
$content=$_POST['content'];
$link=mysqli_connect('localhost','root','','a');
//然后是指定php鏈接數(shù)據(jù)庫的字符集
mysqli_set_charset($link,'utf8');
$sql = "INSERT INTO search(content)
VALUES ('{$content}')";
 
$result=mysqli_query($link,$sql);
echo "<script>alert('創(chuàng)建成功');</script>";
?>

以上就是PHP連接數(shù)據(jù)庫實現(xiàn)頁面增刪改查效果的詳細(xì)內(nèi)容,更多關(guān)于PHP增刪改查的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評論

伊金霍洛旗| 民乐县| 炎陵县| 张家界市| 江安县| 彰化市| 宜春市| 武鸣县| 利津县| 五峰| 尤溪县| 武城县| 阆中市| 遂昌县| 崇礼县| 扶余县| 侯马市| 玉树县| 光泽县| 六枝特区| 南平市| 皮山县| 三门县| 陆丰市| 射洪县| 年辖:市辖区| 花莲县| 九寨沟县| 黄浦区| 临沂市| 邯郸市| 玉溪市| 临海市| 潼关县| 拜城县| 固始县| 固安县| 芦溪县| 荆门市| 广西| 赣榆县|