php 개발 게시판 CRUD 조작

5854 단어 php 개발메모판
프로젝트 구성:

페이지 추가:                                설명:여 기 는 조작 만 중시 하고 인터페이스의 미 공 에 공 을 들 이지 않 았 습 니 다.이해 해 주 십시오.

목록 페이지:

페이지 수정:
프로젝트 에 필요 한 sql:
 
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
 
<?php
$conn = @ mysql_connect("localhost", "root", "") or die(" ");
mysql_select_db("form", $conn);
mysql_query("set names 'gbk'");
?>
add.php
 
<?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);

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

if(addForm.user.value==""){
alert(" ");
addForm.user.focus();
return false;
}
if(addForm.title.value.length<5){
alert(" 5 ");
addForm.title.focus();
return false;
}
}
</script>
<FORM name="addForm" METHOD="POST" ACTION="add.php" onsubmit="return checkPost();">
:<INPUT TYPE="text" NAME="user" /><br />
:<INPUT TYPE="text" NAME="title" /><br />
:<TEXTAREA NAME="content" ROWS="8" COLS="30"></TEXTAREA><br />
<INPUT TYPE="submit" name="submit" value="add" /></FORM>
list.php
 
<?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>&nbsp;&nbsp;|&nbsp;&nbsp;<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 }?>
post Edit.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>";
?>

좋은 웹페이지 즐겨찾기