PHP增刪改查項(xiàng)目的實(shí)戰(zhà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ù)庫(kù)的字符集
mysqli_set_charset($link,'utf8');
$sql="select * from search";
//模糊查詢出像數(shù)據(jù)庫(kù)中的title或者content里面的值或者說(shuō)像數(shù)據(jù)庫(kù)中的title或者content里面的某一段值相對(duì)應(yīng)的就行了,就可以輸出啦
$result=mysqli_query($link,$sql);//運(yùn)行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)) {//把對(duì)象編程數(shù)組輸出,不然會(huì)報(bào)錯(cuò)哦
# code...
?>
<tr>
<td><?=$row['id'];?></td>
<td><?=$row['content'];?></td>
<td><a href="update.php?id=<?php echo $row['id']; ?>">更新</a></td>
<td><a href="delete.php?id=<?php echo $row['id']; ?>">刪除</a></td>
<td><a href="create.php">創(chuàng)建</a></td>
</tr>
<?php
}
?>
</tr>
</table>
</body>
</html>
delete.php
<?php
$link=mysqli_connect('localhost','root','','a');
//然后是指定php鏈接數(shù)據(jù)庫(kù)的字符集
mysqli_set_charset($link,'utf8');
//$sql = "DELETE FROM `search` WHERE `id` = '$_POST[id]'";
//模糊查詢出像數(shù)據(jù)庫(kù)中的title或者content里面的值或者說(shuō)像數(shù)據(jù)庫(kù)中的title或者content里面的某一段值相對(duì)應(yīng)的就行了,就可以輸出啦
$result=mysqli_query($link,"DELETE FROM search WHERE id ='$_GET[id]'");//運(yùn)行sql
$sql="select * from search";
//模糊查詢出像數(shù)據(jù)庫(kù)中的title或者content里面的值或者說(shuō)像數(shù)據(jù)庫(kù)中的title或者content里面的某一段值相對(duì)應(yīng)的就行了,就可以輸出啦
$result=mysqli_query($link,$sql);//運(yùn)行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)) {//把對(duì)象編程數(shù)組輸出,不然會(huì)報(bào)錯(cuò)哦
# code...
?>
<tr>
<td><?=$row['id'];?></td>
<td><?=$row['content'];?></td>
<td><a href="update.php?id=<?= $row['id']; ?>">更新</a></td>
<td><a href="delete.php?id=<?= $row['id']; ?>">刪除</a></td>
<td><a href="create.php">創(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ù)庫(kù)的字符集
mysqli_set_charset($link,'utf8');
//$sql = "DELETE FROM `search` WHERE `id` = '$_POST[id]'";
//模糊查詢出像數(shù)據(jù)庫(kù)中的title或者content里面的值或者說(shuō)像數(shù)據(jù)庫(kù)中的title或者content里面的某一段值相對(duì)應(yīng)的就行了,就可以輸出啦
$result=mysqli_query($link,"UPDATE search set content='$_GET[content]' WHERE id ='$_GET[id]'");//運(yùn)行sql
$sql="select * from search";
//模糊查詢出像數(shù)據(jù)庫(kù)中的title或者content里面的值或者說(shuō)像數(shù)據(jù)庫(kù)中的title或者content里面的某一段值相對(duì)應(yīng)的就行了,就可以輸出啦
$result=mysqli_query($link,$sql);//運(yùn)行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)) {//把對(duì)象編程數(shù)組輸出,不然會(huì)報(bào)錯(cuò)哦
# code...
?>
<tr>
<td><?=$row['id'];?></td>
<td><?=$row['content'];?></td>
<td><a href="update.php?id=<?= $row['id']; ?>">更新</a></td>
<td><a href="delete.php?id=<?= $row['id']; ?>">刪除</a></td>
<td><a href="create.php">創(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ù)庫(kù)的字符集
mysqli_set_charset($link,'utf8');
$sql = "INSERT INTO search(content)
VALUES ('{$content}')";
$result=mysqli_query($link,$sql);
echo "<script>alert('創(chuàng)建成功');</script>";
?>
總結(jié)
本篇文章就到這里了,希望能夠給你帶來(lái)幫助,也希望您能夠多多關(guān)注腳本之家的更多內(nèi)容!
相關(guān)文章
PHP實(shí)現(xiàn)抽獎(jiǎng)功能實(shí)例代碼
這篇文章主要介紹了PHP如何實(shí)現(xiàn)抽獎(jiǎng)功能,文中示例代碼非常詳細(xì),供大家參考和學(xué)習(xí),感興趣的朋友可以了解下2020-06-06
Mac版PhpStorm之XAMPP整合apache服務(wù)器配置的圖文教程詳解
選擇在PhpStorm集成apache服務(wù)器,但是很多朋友不知道是如何操作的,下面小編分步驟通過(guò)圖文的形式給大家介紹Mac版PhpStorm之XAMPP整合apache服務(wù)器配置的教程,感興趣的朋友一起看看吧2016-10-10
php微信公眾平臺(tái)開(kāi)發(fā)之獲取用戶基本信息
本文介紹如何獲得微信公眾平臺(tái)關(guān)注用戶的基本信息,包括昵稱、頭像、性別等基本信息。下面小編把最近整理有關(guān)php微信公眾平臺(tái)開(kāi)發(fā)之獲取用戶基本信息的相關(guān)內(nèi)容分享給大家,有需要的朋友可以參考下2015-08-08
Laravel 5.5基于內(nèi)置的Auth模塊實(shí)現(xiàn)前后臺(tái)登陸詳解
最近在使用laravel5.5,利用其實(shí)現(xiàn)了一個(gè)功能,下面分享給大家,這篇文章主要給大家介紹了關(guān)于Laravel 5.5基于內(nèi)置的Auth模塊如何實(shí)現(xiàn)前后臺(tái)登陸的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。2017-12-12
PHP使Laravel為JSON REST API返回自定義錯(cuò)誤的問(wèn)題
這篇文章主要介紹了PHP使Laravel為JSON REST API返回自定義錯(cuò)誤的問(wèn)題,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-10-10

