search
Homephp教程php手册php开发_留言板的CRUD(增,删,改,查)操作 - jerrylsxu

项目结构:

添加页面:                                说明:这里只注重操作,对界面的美工没有下工夫,希望大家理解......

列表页面:

修改页面:

项目中所需的sql:

复制代码
 1 create database form;
 2 
 3 use form;
 4 
 5 CREATE TABLE `message` (
 6   `id` tinyint(1) NOT NULL auto_increment,
 7   `user` varchar(25) NOT NULL,
 8   `title` varchar(50) NOT NULL,
 9   `content` tinytext NOT NULL,
10   `lastdate` date NOT NULL,
11   PRIMARY KEY  (`id`)
12 ) ENGINE=InnoDB DEFAULT CHARSET=gbk AUTO_INCREMENT=1 ;
复制代码

conn.php

1 <?php 2 $conn = @ mysql_connect("localhost", "root", "") or die("数据库链接错误");
3 mysql_select_db("form", $conn);
4 mysql_query("set names 'gbk'"); 
5 ?>

add.php

复制代码
 1 <?php 2 include 'conn.php';
 3 if($_POST['submit']){
 4     $sql="INSERT INTO message(id,user,title,content,lastdate) VALUES (NULL, '$_POST[user]', '$_POST[title]', '$_POST[content]', now())";
 5     mysql_query($sql);
 6 
 7     //页面跳转,实现方式为javascript
 8     $url = "list.php";
 9     echo "<script language='javascript' type='text/javascript'>";
10     echo "window.location.href='$url'";
11     echo "";
12 }
13 ?>
14 <script type="text/javascript">
15 function checkPost(){
16 
17     if(addForm.user.value==""){
18         alert("请输入用户名");
19         addForm.user.focus();
20         return false;
21     }
22     if(addForm.title.value.length<5){
23         alert("标题不能少于5个字符");
24         addForm.title.focus();
25         return false;
26         }
27 }
28 </script>
29 
30 用户:
31 标题:
32 内容:
33
复制代码

list.php

复制代码
 1 <?php 2 include 'conn.php';
 3 ?>
 4 <?php 5 echo "<div align='center'><a href="add.php">继续添加</a>
"; 6 ?> 7 8 13 14 15 16 17 18 19 20 21 22 23 24
标题:=$row[title]?> 用户:=$row[user] ?>
编辑  |  删除
内容:=$row[content]?>
发表日期:=$row[lastdate]?>
复制代码

delete.php

复制代码
 1 <?php 2 include 'conn.php';
 3 $id = $_GET['id'];
 4 $query="delete from message where id=".$id;
 5 mysql_query($query);
 6 ?>
 7 <?php 8 //页面跳转,实现方式为javascript
 9 $url = "list.php";
10 echo "<script language='javascript' type='text/javascript'>";
11 echo "window.location.href='$url'";
12 echo "";
13 ?>
复制代码

preEdit.php

复制代码
 1 <?php 2 include 'conn.php';
 3 $id=$_GET[id];
 4 $query="SELECT * FROM message WHERE id =".$id;
 5 $result=mysql_query($query);
 6 while ($rs=mysql_fetch_array($result)){
 7 ?>
 8 
9 10 用户:
11 标题:
12 内容:
13 14
15
复制代码

postEdit.php

复制代码
 1 <?php 2 include 'conn.php';
 3 $query="update message set user='$_POST[user]',title='$_POST[title]',content='$_POST[content]' where id='$_POST[id]'";
 4 mysql_query($query);
 5 ?>
 6 <?php 7 //页面跳转,实现方式为javascript
 8 $url = "list.php";
 9 echo "<script language='javascript' type='text/javascript'>";
10 echo "window.location.href='$url'";
11 echo "";
12 ?>
复制代码

 

Statement
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 AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor