Home Backend Development PHP Tutorial CRUD (add, delete, modify, check) operations for php message board development_PHP tutorial

CRUD (add, delete, modify, check) operations for php message board development_PHP tutorial

Jul 21, 2016 pm 03:18 PM
crud php delete increase right develop operate change check Add to boundary message board of structure illustrate page project

Project structure:

Add page: Explanation: Only pay attention to the operation here, and there is no time for the artist of the interface. I hope everyone understands ...

List page:

Modify page:

SQL required in the project:

Copy code The code is as follows:
create database form;

use form;

CREATE TABLE `message` (
`id` tinyint(1) NOT NULL auto_increment,
`user` varchar(25) NOT NULL,
`title` varchar(50) NOT NULL,
`content` tinytext NOT NULL,
`lastdate` date NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET= gbk AUTO_INCREMENT=1;


conn.php

Copy code The code is as follows:
<?php
$conn = @ mysql_connect("localhost", "root", "") or die("Database link error");
mysql_select_db("form", $conn);
mysql_query("set names 'gbk'");
?>

add.php

Copy code The code is as follows:
<?php
include 'conn.php';
if($_POST['submit']){
$sql="INSERT INTO message(id,user,title,content,lastdate) VALUES (NULL, '$_POST[user]', '$_POST[title]', '$_POST[content]', now())";
mysql_query ($sql);

//Page jump, implemented by javascript
$url = "list.php";
echo "<script language='javascript' type='text /javascript'>";
echo "window.location.href='$url'";
echo "</script>";
}
?>
&lt ;script type="text/javascript">
function checkPost(){

if(addForm.user.value==""){
alert("Please enter username") ;
addForm.user.focus();
return false;
}
if(addForm.title.value.length<5){
alert("The title cannot be less than 5 characters");
addForm.title.focus();
return false;
}
}
</script>
<FORM name="addForm" METHOD= "POST" ACTION="add.php" onsubmit="return checkPost();">
User: <INPUT TYPE="text" NAME="user" /><br />
Title: <INPUT TYPE="text" NAME="title" /><br />
Content: <TEXTAREA NAME="content" ROWS="8" COLS="30"> </TEXTAREA><br />
<INPUT TYPE="submit" name="submit" value="add" /></FORM>

list .php

Copy code The code is as follows:

<?php
include 'conn.php';
?>
<?php
echo "<div align='center'><a href='add.php'>继续添加</a></div>";
?>
<table width=500 border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#add3ef">
<?php
$sql="select * from message order by id";
$query=mysql_query($sql);
while ($row=mysql_fetch_array($query)){
?>

<tr bgcolor="#eff3ff">
<td>标题:<font color="red"><?=$row[title]?></font> 用户:<font color="red"><?=$row[user] ?></font><div align="right"><a href="preEdit.php?id=<?=$row[id]?>">编辑</a>  |  <a href="delete.php?id=<?=$row[id]?>">删除</a></div></td>
</tr>
<tr bgColor="#ffffff">
<td>内容:<?=$row[content]?></td>
</tr>
<tr bgColor="#ffffff">
<td><div align="right">发表日期:<?=$row[lastdate]?></div></td>
</tr>
<?php }?>
</table>

delete.php
复制代码 代码如下:

<?php
include 'conn.php';
$id = $_GET['id'];
$query="delete from message where id=".$id;
mysql_query($query);
?>
<?php
//页面跳转,实现方式为javascript
$url = "list.php";
echo "<script language='javascript' type='text/javascript'>";
echo "window.location.href='$url'";
echo "</script>";
?>

preEdit.php
复制代码 代码如下:

<?php
include 'conn.php';
$id=$_GET[id];
$query="SELECT * FROM message WHERE id =".$id;
$result=mysql_query($query);
while ($rs=mysql_fetch_array($result)){
?>
<FORM METHOD="POST" ACTION="postEdit.php">
<input type="hidden" name="id" value="<?=$rs[id]?>">
用户:<INPUT TYPE="text" NAME="user" value="<?=$rs[user]?>"/><br />
标题:<INPUT TYPE="text" NAME="title" value="<?=$rs[title]?>"/><br />
内容:<TEXTAREA NAME="content" ROWS="8" COLS="30"><?=$rs[content]?></TEXTAREA><br />
<INPUT TYPE="submit" name="submit" value="edit"/>
</FORM>
<?php }?>

postEdit.php
复制代码 代码如下:

<?php
include 'conn.php';
$query="update message set user='$_POST[user]',title='$_POST[title]',content='$_POST[content]' where id='$_POST[id]'";
mysql_query($query);
?>
<?php
//页面跳转,实现方式为javascript
$url = "list.php";
echo "<script language='javascript' type='text/javascript'>";
echo "window.location.href='$url'";
echo "</script>";
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/325343.htmlTechArticle项目结构: 添加页面: 说明:这里只注重操作,对界面的美工没有下工夫,希望大家理解...... 列表页面: 修改页面: 项目中所需的sql:...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

How To Set Up Visual Studio Code (VS Code) for PHP Development

See all articles