Home >Backend Development >PHP Tutorial >PHP simple message board program code_PHP tutorial
This is the most basic message board program, but it already has the basic functions of the message board program. It is very suitable for PHP beginners to use for learning. Of course, it can also be used for corporate websites, which is also very good. .
The code is as follows | Copy code | |||||||
session_start(); $pagesize = 10;//How many message records are displayed on each page $sql = "SELECT a . * , b.name, b.email, b.qq, c.revert_time, c.revert $recordSql = $sql. " LIMIT ".$page*$pagesize.",".$pagesize;
post.php file
header('content-type:text/html;charset=utf-8'); $name = $_POST['name']; if($name==""||strlen($name)>10){ //Link database //Insert customer information into the guest table //Insert the customer ID and message information obtained by the above insertion into the post table |
The following is the backend management page login.php to log in first
代码如下 | 复制代码 | |
session_start(); if(isset($_POST['Submit'])){ if(!get_magic_quotes_gpc()){ foreach ($_POST as &$items){ $items = addslashes($items); } } if($_POST['username']=='phpiask'&&md5($_POST['password'])=='6dc88b87062a5de19895e952fa290dad'){ $_SESSION['login']=true; echo "<script>alert('管理员登录成功');location.href='index.php';</script>"; exit(); } else { echo "<script>alert('登录失败!');</script>"; } } ?> |
delete.php to delete messages
The code is as follows | Copy code | ||||
header('content-type:text/html;charset=utf-8'); $con=mysql_connect('localhost','root','root') or die('Failed to connect to database!'); mysql_query('set names utf8'); mysql_select_db('GuestBook'); if(!$_SESSION['login']){ echo "<script>alert('Insufficient permissions!');location.href='index.php';</script>"; exit(); } if(isset($_GET['id'])&&$_GET['id']!=""){ $delRevertSql="delete from revert where post_id=".$_GET['id']; mysql_query($delRevertSql); $delGuestSql="delete from guest where id = (select guest_id from post where id=".$_GET['id'].")"; mysql_query($delGuestSql); $delPostSql="delete from post where id=".$_GET['id']; mysql_query($delPostSql); if(mysql_error()==""){ echo "<script>alert('Delete successfully!');location.href='index.php';</script>"; } } ?> |
revert.php file for replying to messages
The code is as follows
|
Copy code | |||||
if(!$_SESSION['login']){
echo "<script>alert('Cannot reply without logging in!');location.href='index.php';</script>";
exit();
}
if($_POST['Submit']){
if(!get_magic_quotes_gpc()){
foreach ($_POST as $items){
$items = addslashes($items);
}
}
if(strlen($_POST['revert'])>400){
echo "<script>alert('Reply too long!');history.go(-1);</script>";
exit();
}
$post_id = $_POST['post_id'];
$revert = $_POST['revert'];
$insertRevertSql = "insert into revert (post_id,revert,revert_time) value('$post_id','$revert','$time')";
if(mysql_query($insertRevertSql)){
echo "<script>alert('reply successfully');location.href='index.php';</script>";
exit();
}
else {
echo "<script>alert('Reply failed!');history.go(-1);</script>";
}
}
?>