php mysql 留言本应用实例

<div class="codetitle"><a style="CURSOR: pointer" data="29745" class="copybut" id="copybut29745" onclick="doCopy('code29745')"> 代码如下:

<div class="codebody" id="code29745">
<?PHP
$hostname_conn = "localhost";
$database_conn = "test";
$username_conn = "root";
$password_conn = "1981427";
$conn = MysqL_connect($hostname_conn,$username_conn,$password_conn);
?>

<div class="codetitle"><a style="CURSOR: pointer" data="21459" class="copybut" id="copybut21459" onclick="doCopy('code21459')"> 代码如下:
<div class="codebody" id="code21459">
<?PHP
//该函数用于将一般字符串转换sql语句所需要的格式
function GetsqlValueString($theValue,$theType)
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
}
return $theValue;
}
?>

<div class="codetitle"><a style="CURSOR: pointer" data="99432" class="copybut" id="copybut99432" onclick="doCopy('code99432')"> 代码如下:
<div class="codebody" id="code99432">
<?PHP
session_start(); //如果Session不存在,则跳转到Admin.PHP
if (!(isset($_SESSION['MM_Username']))) {
header("Location: admin.PHP");
exit;
}
?>

<div class="codetitle"><a style="CURSOR: pointer" data="38953" class="copybut" id="copybut38953" onclick="doCopy('code38953')"> 代码如下:<div class="codebody" id="code38953">
<?php require_once('Connections/conn.php'); ?>
<?PHP
// *** Validate request to login to this site.
session_start(); $loginFormAction = $_SERVER['PHP_SELF'];
if (isset($accesscheck)) {
$GLOBALS['PrevUrl'] = $accesscheck;
session_register('PrevUrl');
} if (isset($_POST['username'])) {
$loginUsername=$_POST['username'];
$password=$_POST['password'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "adminmain.PHP";
$MM_redirectLoginFailed = "admin.PHP";
$MM_redirecttoReferrer = false;
MysqL_select_db($database_conn,$conn); $LoginRSquery=sprintf("SELECT adminname,password FROM admin WHERE adminname='%s' AND password='%s'",
get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername),get_magic_quotes_gpc() ? $password : addslashes($password)); $LoginRS = MysqL_query($LoginRS
query,$conn) or die(MysqL_error());
$loginFoundUser = MysqL_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = ""; //declare two session variables and assign them
$GLOBALS['MM_Username'] = $loginUsername;
$GLOBALS['MM_UserGroup'] = $loginStrGroup; //register the session variables
session_register("MM_Username");
session_register("MM_UserGroup"); if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;


Untitled Document
<Meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css"><style type="text/css" bogus="1">.style1 {font-size: 18px;
font-weight: bold;
}
.style2 {font-size: 14px}

<p align="center"><span class="style1">留言板 - 管理登陆


<p align="center"><span class="style2"><a href="viewposts.php" href="viewposts.php">浏览留言 | <a href="newpost.php" href="newpost.php">发表留言


<form name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
<table width="239" border="0" align="center">
<tr>
<td width="73">用户名:</td>
<td width="156"><input name="username" type="text" id="username"></td>
</tr>
<tr>
<td>密码:</td>
<td><input name="password" type="password" id="password"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="提交">
<input type="reset" name="Submit2" value="重设"></td>
</tr>
</table>

<p align="center">




<div class="codetitle"><a style="CURSOR: pointer" data="20391" class="copybut" id="copybut20391" onclick="doCopy('code20391')"> 代码如下:<div class="codebody" id="code20391">
<?PHP require_once('Connections/conn.PHP');
require_once('inc/accesscheck.PHP');
require_once('inc/GetsqlValueString.PHP');?>
<?PHP
if ((isset($_GET['postid'])) && ($_GET['postid'] != "")) {
$updatesql = sprintf("UPDATE posts SET checked=1-checked WHERE postid=%s",
GetsqlValueString($_GET['postid'],"int")); MysqL_select_db($database_conn,$conn);
$Result1 = MysqL_query($updatesql,$conn) or die(MysqL_error()); $deleteGoTo = "adminmain.PHP";
if (isset($_SERVER['QUERY_STRING'])) {
$deleteGoTo .= (strpos($deleteGoTo,'?')) ? "&" : "?";
$deleteGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s",$deleteGoTo));
}
?>

<div class="codetitle"><a style="CURSOR: pointer" data="2637" class="copybut" id="copybut2637" onclick="doCopy('code2637')"> 代码如下:<div class="codebody" id="code2637">
<?PHP
require_once('Connections/conn.PHP');
require_once('inc/accesscheck.PHP');
require_once('inc/GetsqlValueString.PHP');
?>
<?PHP
if ((isset($_GET['postid'])) && ($_GET['postid'] != "")) {
$deletesql = sprintf("DELETE FROM posts WHERE postid=%s",$conn);
$Result1 = MysqL_query($deletesql,$deleteGoTo));
}
?>

<div class="codetitle"><a style="CURSOR: pointer" data="29340" class="copybut" id="copybut29340" onclick="doCopy('code29340')"> 代码如下:<div class="codebody" id="code29340">
<?PHP require_once('Connections/conn.PHP');
require_once('inc/accesscheck.PHP');
require_once('inc/GetsqlValueString.PHP');?>
<?PHP
if ((isset($_GET['postid'])) && ($_GET['postid'] != "")) {
$deletesql = sprintf("UPDATE posts SET replied=0,adminname='',replycontent='' WHERE postid=%s",$deleteGoTo));
}
?>

<div class="codetitle"><a style="CURSOR: pointer" data="49230" class="copybut" id="copybut49230" onclick="doCopy('code49230')"> 代码如下:<div class="codebody" id="code49230">
<?PHP require_once('Connections/conn.PHP');
require_once('inc/accesscheck.PHP');
require_once('inc/GetsqlValueString.PHP');?>
<?PHP
MysqL_select_db($database_conn,$conn);
$query_rs = "SELECT FROM posts ORDER BY postid DESC";
$rs = MysqL_query($query_rs,$conn) or die(MysqL_error());
$row_rs = MysqL_fetch_assoc($rs);
$totalRows_rs = MysqL_num_rows($rs);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;


Untitled Document
<Meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css"><style type="text/css" bogus="1">.style1 {font-size: 18px;
font-weight: bold;
}
.style2 {font-size: 14px}
.style4 {font-size: 12px}
.style6 {font-size: 12px; font-weight: bold; }

<p align="center"><span class="style1">留言板 - 管理页面


<p align="center"><span class="style2"><a href="viewposts.php" href="viewposts.php">浏览留言 | <a href="newpost.php" href="newpost.php">发表留言 | <a href="logout.php" href="logout.php">退出登陆


<p align="center">


<table width="623" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="91"><span class="style6">留言者用户名
</td>
<td width="210"><span class="style6">留言标题
</td>
<td width="61"> </td>
<td width="61"> </td>
<td width="61"> </td>
<td width="62"> </td>
</tr>
<?php do { ?>
<tr>
<td><span class="style4"><?php echo $row_rs['username']; ?></td>
<td><span class="style4"><?php
echo $row_rs['topic'];
if($row_rs['checked']==1)
echo "(已审批)";
if($row_rs['replied']==1)
echo "(已回复)";
?></td>
<td><div align="center"><span class="style4"><a href="adminreply.php?postid=<?php echo $row_rs['postid']; ?>">回复留言</td>
<td><div align="center"><span class="style4"><a href="admindelpost.php?postid=<?php echo $row_rs['postid']; ?>">删除留言</td>
<td><div align="center"><span class="style4"><a href="admindelreply.php?postid=<?php echo $row_rs['postid']; ?>">删除回复</td>
<td><div align="center"><span class="style4"><a href="admincheckpost.php?postid=<?php echo $row_rs['postid']; ?>">审批留言</td>
</tr>
<?php } while ($row_rs = mysql_fetch_assoc($rs)); ?>
</table>
<p align="center">




<?PHP
MysqL_free_result($rs);
?>

<div class="codetitle"><a style="CURSOR: pointer" data="16118" class="copybut" id="copybut16118" onclick="doCopy('code16118')"> 代码如下:<div class="codebody" id="code16118">
<?PHP require_once('Connections/conn.PHP');
require_once('inc/accesscheck.PHP');
require_once('inc/GetsqlValueString.PHP');?>
<?PHP
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
} if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updatesql = sprintf("UPDATE posts SET replycontent=%s,replied=1,checked=1,adminname=%s WHERE postid=%s",
GetsqlValueString($_POST['replycontent'],"text"),
GetsqlValueString($_SESSION['MM_Username'],
GetsqlValueString($_POST['postid'],$conn) or die(MysqL_error()); echo "<script type="text/javascript">";
} $colname_rs = "1";
if (isset($_GET['postid'])) {
$colname_rs = (get_magic_quotes_gpc()) ? $_GET['postid'] : addslashes($_GET['postid']);
}
MysqL_select_db($database_conn,$conn);
$query_rs = sprintf("SELECT
FROM posts WHERE postid = %s",$colname_rs);
$rs = MysqL_query($query_rs,$conn) or die(MysqL_error());
$row_rs = MysqL_fetch_assoc($rs);
$totalRows_rs = MysqL_num_rows($rs);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;


Untitled Document
<Meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css"><style type="text/css" bogus="1">.style1 {font-size: 18px;
font-weight: bold;
}
.style2 {font-size: 14px}

<p align="center"><span class="style1">留言板 - 管理页面 - 回复留言


<p align="center"><span class="style2"><a href="adminmain.php" href="adminmain.php">管理页面<a href="newpost.php" href="newpost.php"> | <a href="logout.php" href="logout.php">退出登陆

<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td nowrap align="right" valign="top">留言标题:</td>
<td><?php echo $row_rs['topic']; ?></td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top">留言内容:</td>
<td><?php echo $row_rs['content']; ?></td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top">回复内容:</td>
<td>
<textarea name="replycontent" cols="50" rows="5"><?php echo $row_rs['replycontent']; ?>

<div class="codetitle"><a style="CURSOR: pointer" data="15454" class="copybut" id="copybut15454" onclick="doCopy('code15454')"> 代码如下:<div class="codebody" id="code15454">
<?PHP
$logoutGoTo = "admin.PHP";
session_start();
unset($_SESSION['MM_Username']);
unset($_SESSION['MM_UserGroup']);
if ($logoutGoTo != "") {header("Location: $logoutGoTo");
session_unregister('MM_Username');
session_unregister('MM_UserGroup');
exit;
}
?>
<?PHP
$logoutGoTo = "admin.PHP";
session_start();
unset($_SESSION['MM_Username']);
unset($_SESSION['MM_UserGroup']);
if ($logoutGoTo != "") {header("Location: $logoutGoTo");
session_unregister('MM_Username');
session_unregister('MM_UserGroup');
exit;
}
?>

<div class="codetitle"><a style="CURSOR: pointer" data="90887" class="copybut" id="copybut90887" onclick="doCopy('code90887')"> 代码如下:<div class="codebody" id="code90887">
<?PHP require_once('Connections/conn.PHP');
require_once('inc/GetsqlValueString.PHP');?>
<?PHP
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
} if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertsql = sprintf("INSERT INTO posts (username,topic,content) VALUES (%s,%s,%s)",
GetsqlValueString($_POST['username'],
GetsqlValueString($_POST['topic'],
GetsqlValueString($_POST['content'],"text")); MysqL_select_db($database_conn,$conn);
$Result1 = MysqL_query($insertsql,$conn) or die(MysqL_error()); echo "<script type="text/javascript">";
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;


Untitled Document
<Meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css"><style type="text/css" bogus="1">.style1 { font-size: 18px;
font-weight: bold;
}
.style2 {font-size: 14px}

<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<p align="center"><span class="style1">留言板 - 发表新留言


<p align="center"><span class="style2"><a href="viewposts.php" href="viewposts.php">浏览留言 | <a href="admin.php" href="admin.php">管理登陆


<table align="center">
<tr valign="baseline">
<td Nowrap align="right">用户名:</td>
<td><input type="text" name="username" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td Nowrap align="right">标题:</td>
<td><input type="text" name="topic" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td Nowrap align="right" valign="top">留言内容:</td>
<td>
<textarea name="content" cols="50" rows="5">
<?PHP require_once('Connections/conn.PHP');
require_once('inc/GetsqlValueString.PHP');?>
<?PHP
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
} if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertsql = sprintf("INSERT INTO posts (username,$conn) or die(MysqL_error()); echo "<script type="text/javascript">";
}
?>

<div class="codetitle"><a style="CURSOR: pointer" data="64588" class="copybut" id="copybut64588" onclick="doCopy('code64588')"> 代码如下:<div class="codebody" id="code64588">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;


Untitled Document
<Meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css"><style type="text/css" bogus="1">.style1 {font-size: 18px;
font-weight: bold;
}
.style2 {font-size: 14px}

<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<p align="center"><span class="style1">留言板 - 发表新留言


<p align="center"><span class="style2"><a href="viewposts.php" href="viewposts.php">浏览留言 | <a href="admin.php" href="admin.php">管理登陆


<table align="center">
<tr valign="baseline">
<td Nowrap align="right">用户名:</td>
<td><input type="text" name="username" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td Nowrap align="right">标题:</td>
<td><input type="text" name="topic" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td Nowrap align="right" valign="top">留言内容:</td>
<td>
<textarea name="content" cols="50" rows="5">

<div class="codetitle"><a style="CURSOR: pointer" data="16927" class="copybut" id="copybut16927" onclick="doCopy('code16927')"> 代码如下:<div class="codebody" id="code16927">
<?php require_once('Connections/conn.php'); ?>
<?PHP
$currentPage = $_SERVER["PHP_SELF"]; $maxRows_rs = 10;
$pageNum_rs = 0;
if (isset($_GET['pageNum_rs'])) {
$pageNum_rs = $_GET['pageNum_rs'];
}
$startRow_rs = $pageNum_rs $maxRows_rs; MysqL_select_db($database_conn,$conn);
$query_rs = "SELECT
FROM posts WHERE checked=1 ORDER BY postid DESC";
$query_limit_rs = sprintf("%s LIMIT %d,%d",$query_rs,$startRow_rs,$maxRows_rs);
$rs = MysqL_query($query_limit_rs,$conn) or die(MysqL_error());
$row_rs = MysqL_fetch_assoc($rs); if (isset($_GET['totalRows_rs'])) {
$totalRows_rs = $_GET['totalRows_rs'];
} else {
$all_rs = MysqL_query($query_rs);
$totalRows_rs = MysqL_num_rows($all_rs);
}
$totalPages_rs = ceil($totalRows_rs/$maxRows_rs)-1; $queryString_rs = "";
if (!emptyempty($_SERVER['QUERY_STRING'])) {
$params = explode("&",$_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param,"pageNum_rs") == false &&
stristr($param,"totalRows_rs") == false) {
array_push($newParams,$param);
}
}
if (count($newParams) != 0) {
$queryString_rs = "&" . htmlentities(implode("&",$newParams));
}
}
$queryString_rs = sprintf("&totalRows_rs=%d%s",$totalRows_rs,$queryString_rs);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;


Untitled Document
<Meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css"><style type="text/css" bogus="1">.style1 {
font-size: 18px;
font-weight: bold;
}
.style2 {font-size: 14px}

<p align="center" class="style1">留言板 - 留言浏览


<p align="center" class="style2"><a href="newpost.php" href="newpost.php">发表留言 | <a href="admin.php" href="admin.php">管理登陆


<?php do { ?>
<table width="500" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="116"><div align="right">

用户名

</td>
<td width="378"><?php echo $row_rs['username']; ?></td>
</tr>
<tr>
<td><div align="right">

标题

</td>
<td><?php echo $row_rs['topic']; ?></td>
</tr>
<tr>
<td><div align="right">

留言内容

</td>
<td><?php echo $row_rs['content']; ?></td>
</tr>
<?php if($row_rs['replied']==1) { ?>
<tr>
<td><div align="right">

回复

</td>
<td>

<?php echo $row_rs['replycontent']; ?>


<p align="right">

回复人:

<?php echo $row_rs['adminname']; ?>

</td>
</tr>
<?php } ?>
</table>


<?php } while ($row_rs = mysql_fetch_assoc($rs)); ?>
<p align="center">
<table border="0" width="50%" align="center">
<tr>
<td width="23%" align="center">
<?php if ($pageNum_rs > 0) { // Show if not first page ?>
<a href="<?php printf(" href="<?php printf("%s?pageNum_rs=%d%s",$currentPage,$queryString_rs); ?>">首页
<?php } // Show if not first page ?>
</td>
<td width="31%" align="center">
<?php if ($pageNum_rs > 0) { // Show if not first page ?>
<a href="<?php printf(" href="<?php printf("%s?pageNum_rs=%d%s",max(0,$pageNum_rs - 1),$queryString_rs); ?>">上一页
<?php } // Show if not first page ?>
</td>
<td width="23%" align="center">
<?PHP if ($pageNum_rs < $totalPages_rs) { // Show if not last page ?>
<a href="<?php printf(" href="<?php printf("%s?pageNum_rs=%d%s",min($totalPages_rs,$pageNum_rs + 1),$queryString_rs); ?>">下一页
<?php } // Show if not last page ?>
</td>
<td width="23%" align="center">
<?PHP if ($pageNum_rs < $totalPages_rs) { // Show if not last page ?>
<a href="<?php printf(" href="<?php printf("%s?pageNum_rs=%d%s",$totalPages_rs,$queryString_rs); ?>">尾页
<?php } // Show if not last page ?>
</td>
</tr>
</table>





<?PHP
MysqL_free_result($rs);
?>

mysql留言本

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...