PHP Simple Message Board tutorial two

Source: Internet
Author: User

Okay, now let's look at the program code for the login.php file.

<?php
Session_Start ();
Include ("global.php");

if (isset ($_post[' username ')) && isset ($_post[' pwd '])
{
$result = mysql_query ("SELECT * from Xx_admin");
if ($info = mysql_fetch_array ($result))
{
if ($_post[' username '] = = $info [' username '] && $info [' password '] = = MD5 ($_post[' pwd '])
{
$_session[user] = $info [' username '];
Echo ("Login ok!");
Die ("<script>window.location.href= ' index.php ';</script>");
}
else echo (' <script>window.alert Login failed! '); window.location.href= '. $_server[' php_self '. "'; </script> ");
}
}
?>

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title> Admin Login </title>
<style type= "Text/css" >
<!--
Body {
Background: #EAF4FF;
font-size:12px;
}
-->
</style>

<body>
<table width= "border=" "0" cellspacing= "0" cellpadding= "0" align= "center" >
<form action= "<?php echo $_server[' php_self ';?>" method= "POST" name= "login" id= "Login" >
<tr>
&LT;TD height= "></td>"
&LT;TD height= ><strong> Admin Login </strong></td>
</tr>
<tr>
&LT;TD width= "height=" align= "right" > Username:&nbsp;</td>
&LT;TD width= "181" height= "><label>"
<input name= "username" type= "text" class= "Loginput" id= "username" "value=" "/>"
</label></td>
</tr>
<tr>
&LT;TD height= "align=" "right" > Password:&nbsp;</td>
&LT;TD height= "><label>"
<input name= "pwd" type= "password" class= "Loginput" id= "pwd"/>
</label></td>
</tr>
<tr>
&LT;TD height= ">&nbsp;</td>"
&LT;TD height= "><label>"
<input name= "Submit" type= "submit" class= "Botton" value= "Login"/>
</label></td>
</tr>
</form>
</table>
</body>

After landing will be able to see the message will be used mreplay.php to answer the questions of netizens. The code is as follows.

<?php
Session_Start ();
Include ("global.php");
if (!$_session[user])
Die ("<script>window.alert") (' please log in first! '); window.location.href= ' login.php ';</script> ');

if (Isset ($_get[' act ')) && $_get[' act ']== ' reply ')
{

$content = $_post[' reply '];
$content = Str_replace ("", "&nbsp;", $content);
$content = Str_replace ("", "&nbsp;", $content);
$content = Str_replace ("\ n", "<br/>", $content);
$sql = "UPDATE xx_guestbook SET reply = ' {$content} ', Replytime = '". Date (' y-m-d h:i:s '). "' WHERE mid = ". Intval ($_get[' mid ']);
Echo $sql;
$row =mysql_query ($sql);
if ($row)
{
Echo ("Reply ok!");
Die ("<script>window.location.href= ' lyb.php ';</script>");
}
else echo ("false");

}else

if (Isset ($_get[' act ')) && $_get[' act ' = = ' edit ')
{
if (Isset ($_get[' mid '))
{
$mid = Intval ($_get[' mid ']);
$row =mysql_query ("select * from Xx_guestbook WHERE mid = {$mid}");
if ($row)
{
$rs =mysql_fetch_array ($row);
Print_r ($RS); DEBUG
echo "<meta http-equiv=\" refresh\ "content=\" 1; Url=index2.php\ ">";
$reply = $rs [' reply '];
$reply = Str_replace ("<br/>", "\ n", $reply);
$reply = Str_replace ("&nbsp;", "", $reply);
$reply = Str_replace ("&nbsp;", "", $content);
$reply = Str_replace ("<br/>", "", $reply);
}
else echo ("false");
}


?>


<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title> Editorial Reply Message </title>

<body>
<table width= "border=" 0 "cellspacing=" 0 "cellpadding=" 0 "align=" center ">
<form action= "<?php $_server[' php_self '];? >?act=reply&amp;mid=<?php Echo (" {$rs [' Mid ']} ");? > "method=" Post "name=" id= "message" >
<tr>
&LT;TD height= align= "center" ><strong> reply message <?php echo $_get[' mid ';?></strong></td>
</tr>
<tr>
&LT;TD height= "align=" "Center" ><label>
<textarea name= "Reply" cols= "" rows= "" class= "input" id= "reply" ><?php echo $reply?></textarea>
</label></td>
</tr>
<tr>
&LT;TD height= "align=" "Center" ><label>
<input name= "Submit" type= "submit" class= "Botton" value= "reply message"/>
</label></td>
</tr>
</form>
</table>
</body>

<?php
}
?>

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.