MySQL-based forum (3) _php tutorial

Source: Internet
Author: User
Tags setcookie administrator password
#####################
# func.php #########
####################
Require ("config.inc.php");
##### Check if the user exists #####
function Is_user_exits ($name) {
$name =trim ($name);
$name =ereg_replace ("'", "'", $name);
$name =htmlspecialchars ($name);
$SQL = "SELECT name from user WHERE name= ' $name '";
$result =mysql_query ($SQL) or Die (Mysql_error ());
$row =mysql_fetch_array ($result);
$name = $row [name];
return $name;
}
##### Check if the layout exists #####
function Is_board_exits ($baord) {
$sql = "SELECT name from Boardinfo where name= ' $baord '";
$result =mysql_query ($sql) or Die ("error occurred");
$row =mysql_fetch_array ($result);
$name = $row [name];
return $name;
}
##### Adding a new user Function #####
function AddUser () {
Global $name, $sex, $realname, $password, $address, $oicq, $homepage, $phone, $email, $QM, $regtime;
$name =trim ($name);
$name =ereg_replace ("'", "'", $name);
$password =trim ($password);
$name =htmlspecialchars ($name);
$realname =htmlspecialchars ($realname);
$address =htmlspecialchars ($address);
$oicq =htmlspecialchars ($OICQ);
$homepage =htmlspecialchars ($homepage);
$phone =htmlspecialchars ($phone);
$email =htmlspecialchars ($email);
$QM =htmlencode2 ($QM);
$regtime =date ("y-m-d h:i:s");
$sql = "INSERT into user (Name,sex,realname,password,address,oicq,homepage,score,phone,email,qm,regtime,slaveboard) VALUES (' $name ', ' $sex ', ' $realname ', ' $password ', ' $address ', ' $oicq ', ' $homepage ', ' 0 ', ' $phone ', ' $email ', ' $qm ', ' $ Regtime ', ') ";
mysql_query ($sql) or Die (Mysql_error ());
}
##### URL Redirection ######
function Redirect2 ($url) {
Header ("Location: $url");
}
##### Creating a layout ######
function create_board_table ($name, $chinesename) {
$name =trim ("$name");
$sql = "CREATE TABLE $name (id int (one) not NULL auto_increment,title varchar (a) not null,writer varchar (a) not Null,cont Lo Ngtext, size int,writetime varchar () not null,hits int (4) Default ' 0 ', good varchar (1), Renum Int (4) Default ' 0 ', SlaveID I NT (one) DEFAULT ' 0 ', fromip varchar, PRIMARY KEY (ID)) ";
mysql_query ($sql);
$sql = "INSERT into Boardinfo (name,chinesename) VALUES (' $name ', ' $chinesename ')";
mysql_query ($sql);
}
###### Delete Layout ######
function Drop_board_table ($name) {
$sql = "drop table $name";
mysql_query ($sql);
$sql = "Delete from Boardinfo where name= ' $name '";
mysql_query ($sql);
}
######## Modify Layout # # #
function Update_board ($name, $chinesename) {
$sql = "Update boardinfo set name= ' $name ', chinesename= ' $chinesename ' where name= ' $name '";
mysql_query ($sql);
}
##### Add Article ######
function Add_doc ($board) {
Global $title, $name, $cont, $writer, $FROMIP, $writetime, $QM, $new _topic_score;
$title =trim ($title);
$title =substr ($title, 0,49);
$size =strlen ($cont);
$cont =htmlencode2 ($cont);
$cont = $cont. "
"." -------
". $qm;
$writetime =date ("y-m-d h:i:s");
$FROMIP =getenv ("remote_addr");
$name =htmlspecialchars ($name);
$writer = $name;
$sql = "INSERT into $board (TITLE,WRITER,CONT,SIZE,WRITETIME,FROMIP) VALUES (' $title ', ' $name ', ' $cont ', ' $size ', ' $ Writetime ', ' $fromip ') ";
mysql_query ($sql);
Add_score ($writer, $new _topic_score);
}
##### Reply Article #####
function Re_doc ($board, $slaveid) {
Global $title, $name, $cont, $writer, $FROMIP, $writetime, $QM, $re _topic_score;
$title =trim ($title);
$title =substr ($title, 0,49);
$size =strlen ($cont);
$cont =htmlencode2 ($cont);
$cont = $cont. "
"." -------
". $qm;
$writetime =date ("y-m-d h:i:s");
$name =htmlspecialchars ($name);
$writer = $name;
$FROMIP =getenv ("remote_addr");
$sql = "INSERT into $board (TITLE,WRITER,CONT,SIZE,WRITETIME,SLAVEID,FROMIP) VALUES (' $title ', ' $writer ', ' $cont ', ' $ Size ', ' $writetime ', ' $slaveid ', ' $fromip ');
mysql_query ($sql);
$sql = "Update $board set renum=renum+1 where id= $slaveid";
mysql_query ($sql);
Add_score ($writer, $re _topic_score);
}
##### Delete Article # # # #
function Del_doc ($board, $id) {
Global $remove _score;
$sql = "SELECT * from $board where id= $id";
$sql _result=mysql_query ($sql);
$sql _row=mysql_fetch_array ($sql _result);
$writer = $sql _row[writer];
Remove_score ($writer, $remove _score);
$slaveid = $sql _row[slaveid];
$sql = "SELECT * from $board where id= $slaveid";
$sql _result=mysql_query ($sql);
$sql _row=mysql_fetch_array ($sql _result);
if ($sql _row[renum]>0) {
$sql = "Update $board set renum=renum-1 where id= $slaveid";
mysql_query ($sql);
}
$sql = "Delete from $board where id= $id";
mysql_query ($sql);
$sql = "Delete from $board where slaveid= $id";
mysql_query ($sql);
}
# # # Convert HTML special characters and
#####
function Htmlencode2 ($STR) {
$str =htmlspecialchars ($STR);
$str =nl2br ($STR);
return $str;
}
##### add a hit # # #
function Add_one_hit ($board, $id) {
$sql = "Update $board set hits=hits+1 where id= $id";
mysql_query ($sql);
}
##### Check User Password # # #
function Check_user_password ($name, $password) {
$name =trim ($name);
$name =ereg_replace ("'", "'", $name);
$name =htmlspecialchars ($name);
$password =trim ($password);
$sql = "Select password from user where name= ' $name '";
$sql _result=mysql_query ($sql);
$sql _row=mysql_fetch_array ($sql _result);
if ($password <> $sql _row[password]) {
$result = 0;
}
else{
$result = 1;
Setcookie ("Jl_forum[name]", $name);
Setcookie ("Jl_forum[password]", $password);
}
return $result;
}
##### Check Administrator Password # # #
function Check_admin_password () {
$sql = "SELECT * from user where name= ' $jl _forum[name] '";
$sql _result=mysql_query ($sql);
$sql _row=mysql_fetch_array ($sql _result);
if ($JL _forum[password]== $sql _row[password]) {
$result = 1;
}
else {
$result = 0;
}
if ($sql _row[slaveboard]== $jl _forum[board]) {
$result = 1;
}
else {
$result = 0;
}
return $result;
}

##### modifying personal Data # # # #
function Change_profile ($name) {
Global $sex, $realname, $password, $address, $oicq, $homepage, $phone, $email, $QM;
$name =trim ($name);
$name =htmlspecialchars ($name);
$realname =htmlspecialchars ($realname);
$address =htmlspecialchars ($address);
$oicq =htmlspecialchars ($OICQ);
$homepage =htmlspecialchars ($homepage);
$phone =htmlspecialchars ($phone);
$email =htmlspecialchars ($email);
$QM =htmlencode2 ($QM);
$sql = "Update user set sex= ' $sex ', realname= ' $realname ', password= ' $password ', address= ' $address ', oicq= ' $oicq ', Homepage= ' $homepage ', phone= ' $phone ', email= ' $email ', qm= ' $qm ' where name= ' $name ' ";
mysql_query ($sql);
}
##### Display error # # # #
function Show_error ($id) {
Redirect2 ("wrong.php?id= $id");
}
##### Add Moderator # # #
function Add_admin ($board, $name) {
$name =trim ($name);
$sql = "Update user set slaveboard= ' $board ' where name= ' $name '";
mysql_query ($sql);
}
##### Delete Moderator #####
function Del_admin ($name) {
$name =trim ($name);
$name =htmlspecialchars ($name);
$sql = "Update user set slaveboard= ' where name= ' $name '";
mysql_query ($sql);
}
##### posts to the Essence # # #
function Set_good ($board, $id) {
$sql = "Update $board set good= ' y ' where id= $id";
mysql_query ($sql);
}
##### turn out the essence # # #
function Set_no_good ($board, $id) {
$sql = "Update $board set good= ' where id= $id";
mysql_query ($sql);
}
##### Export Signature #####
function Expl_qm ($name) {
$name =htmlspecialchars ($name);
$sql = "Select QM from user where name= ' $name '";
$sql _result=mysql_query ($sql);
$sql _row=mysql_fetch_array ($sql _result);
$QM = $sql _ROW[QM];
return $QM;
}
##### Administrator #####
function Adminok () {
if ($jl _admin[name]== $admin _name and $jl _admin[password]== $admin _password) {
return 1;
}
else {
return 0;
}
}
##### Add points #####
function Add_score ($name, $num) {
$name =htmlspecialchars ($name);
$sql = "Update user set score=score+ $num where name= ' $name '";
mysql_query ($sql);
}
##### Reduced Points # # # #
function Remove_score ($name, $num) {
$name =htmlspecialchars ($name);
$sql = "Update user set score=score-$num where name= ' $name '";
mysql_query ($sql);
}
# # # # Send Message # #
function sendmsg () {
Global $fromname, $name, $cont;
$name =htmlspecialchars ($name);
$fromname =htmlspecialchars ($fromname);
$cont =htmlencode2 ($cont);
$WT =date ("y-m-d h:i:s");
$sql = "INSERT into message (Name,fromname,cont,writetime) VALUES (' $name ', ' $fromname ', ' $cont ', ' $wt ')";
mysql_query ($sql);
}
# # # # Delete Message # #
function Delmsg ($id) {
$sql = "Delete from message where id= $id";
mysql_query ($sql);
}
# # # If the message belongs to this person #####
function Is_this_user ($id) {
$sql = "SELECT name from message where id= $id";
$sql _result=mysql_query ($sql);
$sql _row=mysql_fetch_row ($sql _result);
if ($sql _row[name]== $jl _forum[name]) {
return 1;
}
else {
return 0;
}
}
?>
##########################
# good.php ##########
########################
Require ("func.php");
$sql = "SELECT * from Boardinfo";
$sql _result=mysql_query ($sql);
?>


<title>Main</title>



















Forum Essence Area



Forum Information





###########################
# good_list.php ###########
###########################
Require ("func.php");
if (!is_board_exits ($board)) {
$board = "Computer";
}
$sql = "SELECT * from Boardinfo where name= ' $board '";
$sql _result=mysql_query ($sql);
$sql _row=mysql_fetch_array ($sql _result);
$chinesename = $sql _row[chinesename];
Setcookie ("Jl_forum[chinesename]", $chinesename);
$sql = "SELECT name from user where slaveboard= ' $board '";
$sql _result=mysql_query ($sql);
?>


<title>List</title>
















Layout: echo $chinesename;
?> Essence Area
Moderator: While ($sql _row=mysql_fetch_array ($sql _result))
{
echo "$sql _row[name]". ";
}
# Select a message record;
$sql = "SELECT * from $board where good= ' y '";
$temp =mysql_query ($sql);
$sum =mysql_num_rows ($temp);
$totalpage =ceil ($sum/$pagesize);
if ($sum ==0) {
$totalpage = 1;
}
# pagination
if ($page <1 or Empty ($page)) {
$page = 1;
}
ElseIf ($page > $totalpage) {
$page = $totalpage;
}
$offset = ($page-1) * $pagesize;
$sql = "SELECT * from $board the where good= ' y ' ORDER by id desc limit $offset, $pagesize";
$sql _result=mysql_query ($sql);
?>
Total Articles ") ' > "> Refresh Browse


























while ($sql _row=mysql_fetch_array ($sql _result)) {echo " "; Echo "; Echo "; Echo "; Echo "; Echo "; } ? >
Response Topic Time Popularity
";
echo "[*]";
Echo
$sql _row[title]$sql _row[writetime]$sql _row[hits]







############################
# # good_read.php ######
##################### #3
Require ("func.php");
if ($re) {
if (!is_board_exits ($board)) {
Show_error (7);
$founderr = 1;
}
$sql = "Select SlaveID from $board where id= $id";
$sql _result=mysql_query ($sql);
$sql _row=mysql_fetch_array ($sql _result);
if ($sql _row[slaveid]!=0) {
Show_error (1);
$founderr = 1;
}
if (!check_user_password ($name, $password)) {
Show_error (4);
$founderr = 1;
}
if (strlen ($title) >50) {
Show_error (6);
$founderr = 1;
}
if (empty ($title)) {
Show_error (2);
$founderr = 1;
}
if ($QM) {
$QM =EXPL_QM ($name);
}
if (! $founderr) {
Re_doc ($board, $id);
$sql = "SELECT * from $board where id= $id";
$sql _result=mysql_query ($sql);
$sql _row=mysql_fetch_array ($sql _result);
$title = $sql _row[title];
$writer = $sql _row[writer];
$cont = $sql _row[cont];
$writetime = $sql _row[writetime];
$hits = $sql _row[$hits];
$FROMIP = $sql _ROW[FROMIP];
$sql = "SELECT * from $board where slaveid= $id";
$sql _result=mysql_query ($sql);
# $sql _row=mysql_fetch_array ($sql _result);
}

}
ElseIf ($add) {
if (!is_board_exits ($board)) {
Show_error (7);
$founderr = 1;
}
if (empty ($title)) {
Show_error (2);
$founderr = 1;
}
if (!check_user_password ($name, $password)) {
Show_error (4);
$founderr = 1;
}
if (strlen ($title) >50) {
Show_error (6);
$founderr = 1;
}
if ($QM) {
$QM =EXPL_QM ($name);
$founderr = 1;
}
if (! $founderr) {
Add_doc ($board);
}
}
else {
if (!is_board_exits) {
Show_error (7);
}
Add_one_hit ($board, $id);
$sql = "SELECT * from $board where id= $id";
$sql _result=mysql_query ($sql);
$sql _row=mysql_fetch_array ($sql _result);
$title = $sql _row[title];
$writer = $sql _row[writer];
$cont = $sql _row[cont];
$writetime = $sql _row[writetime];
$hits = $sql _row[$hits];
$FROMIP = $sql _ROW[FROMIP];
$sql = "SELECT * from $board where slaveid= $id the ORDER by id DESC";
$sql _result=mysql_query ($sql);
# $sql _row=mysql_fetch_array ($sql _result);
}
?>


<title><?php echo $title;? ></title>























Title:
Author: ( ) ">" >
※ Source: [from: ]







http://www.bkjia.com/PHPjc/316387.html www.bkjia.com true http://www.bkjia.com/PHPjc/316387.html techarticle ##################### # func.php ######### ####################? php require (config.inc.php); ##### Check if the user exists ##### function Is_user_exits ($name) {$name =trim ($name);

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.