登录:
<?php
ob_start();
include('header.html');
print '<body>';
?>
<?php
if($_SERVER['REQUEST_METHOD']=='POST')
{
$_mysqli= new mysqli();
$_mysqli->connect('localhost','root','galgaddott');
$dbc=$_mysqli->select_db('shujuku1');
if($dbc)
{
$query="SELECT * FROM denglu1";
$result=mysqli_query($_mysqli,$query);
if(mysqli_connect_errno($result))
{ print 'can not receive the table!';}
else {
while($row=mysqli_fetch_array($result))//匹配
{ if (($_POST['name']==$row['zhanghao'])&& ($_POST['password']==$row['mima']))
{
setcookie('zhanghao',$_POST['name'],time()+3600,"/");
setcookie('mima',$_POST['password'],time()+3600,"/");
print '登陆成功,页面将于3秒内跳转!';
$_mysqli->close();
header('refresh:3; url=welcome.php');//欢迎界面还没写
exit;}
}
print '请输入正确的管理员账号密码!';
print '信息错误!页面将于3秒内刷新!';
header('refresh:3; url=login1.php');
$_mysqli->close();
exit;
}
}
else print 'can not connect the databases!';
$_mysqli->close();
}
?>
<form action="login1.php" method="post">
<h1 sytle="color:blue;">管理员登录</h1>
<p>账号名:<input type="text" name="name" /></p>
<p>密码:<input type="password" name="password" /></p>
<p><input type="submit" value="确认登录" /></p>
<h3 style="color:yellow;"><a href="zhece.php">注册</a></h3>
<p><a href="welcome.php">游客登录</a></p>
</form>
</body>
</html>
注册:
<?php
ob_start();
include('header.html');
print '<body>';
?>
<form action="zhece.php" method="post">
<p>账号:<input type="text" name="name1" /></p>
<p>密码:<input type="password" name="password1" /></p>
<p><input type="submit" value="确认注册" /></p>
</form>
<?php
error_reporting(0);
if($_SERVER['REQUEST_METHOD']=='POST')
{$_mysqli= new mysqli();
$_mysqli->connect('localhost','root','galgaddott');
$dbc=$_mysqli->select_db('shujuku1');
if($dbc)
{$query="INSERT INTO denglu1(zhanghao,mima) VALUES( {$_POST[name1]},{$_POST[password1]})";
$a=mysqli_query($_mysqli,$query);
if(mysqli_connect_errno($a))
{print '注册失败!于3秒内返回登录界面!';
header('refresh:3; url=login1.php');
exit;
}
else{
setcookie('zhanghao',$_POST['name1'],time()+3600,"/");
setcookie('mima',$_POST['password1'],time()+3600,"/");
print '登陆成功,页面将于3秒内跳转!';
header('refresh:3; url=welcome.php');
exit;
}
}
else {print '注册失败!于3秒内返回登录界面!';
header('refresh:3; url=login1.php');
exit;
}
}
?>
</form>
</body>
</html>
管理员界面:
<?php
ob_start();
include('header.html');
print '<body>';
print '<p style="color:yellow;"><h1> 欢迎来到管理员界面!</h1></p>';
include('footer.html');
?>
添加名言:
<?php
ob_start();
include('header.html');
print '<body>';
if($_SERVER['REQUEST_METHOD']=='POST')
{ if(!empty($_POST['quote'])&&!empty($_POST['source']))
{ include('mysql_connect.php');//调用了连接数据库函数
$quote=mysqli_real_escape_string($_mysqli,trim(strip_tags($_POST['quote'])));
$source=mysqli_real_escape_string($_mysqli,trim(strip_tags($_POST['source'])));
if(isset($_POST['favorite']))
$favorite=1;
else $favorite=0;
$query="INSERT INTO quotes(quote,source,favorite) VALUES ('$quote','$source',$favorite)";
mysqli_query($_mysqli,$query);
if(mysqli_affected_rows($_mysqli)==1)
{print '<p>成功添加!</p>';
print '于3秒内返回管理员界面!';
mysqli_close($_mysqli);
header('refresh:3; url=welcome.php');
exit;}
else {print '添加失败';
print '于3秒内返回管理员界面!';
mysqli_close($_mysqli);
header('refresh:3; url=welcome.php');
exit; }
mysqli_close($_mysqli);
}
else print '<p style="color:red;">没有填写完全!</p>';
}
?>
<form action="add_quote.php" method="post">
<p><label>名言<textarea name="quote" rows="5" cols="30"></textarea></label></p>
<p><label>作者<input type="text" name="source" /></label></p>
<p><label>这是你最喜欢的吗?<input type="checkbox" name="favorite" value="yes" /></label></p>
<input type="submit" name="submit" value="提交"/>
</form>
</body>
</html>
查看所有名言:
<?php
include('header.html');
print '<body>';
print '<h2 style="color:yellow;">所有名言</h2>';
include('mysql_connect.php');
$query='SELECT quote_id,quote,source,favorite FROM quotes ORDER BY date_entered DESC';
if($r=mysqli_query($_mysqli,$query))
{
while($row=mysqli_fetch_array($r))
{ print "<div><blockquote>{$row['quote']}</blockquote>---{$row['source']}\n";
print "<p><a href=\"edit_quote.php?id={$row['quote_id']}\">编辑 </a>
<a href=\"delete_quote.php?id={$row['quote_id']}\">删除</a></p></div>\n";}
}
else {print"显示名言失败!";
print '于3秒内返回管理员界面!';
mysqli_close($_mysqli);
header('refresh:3; url=welcome.php');
exit;
}
mysqli_close($_mysqli);
include('footer.html');
?>
编辑:
<?php
ob_start();
include('header.html');
print '<body>';
include('mysql_connect.php');
if(isset($_GET['id'])&&is_numeric($_GET['id'])&&($_GET['id']>0))//对需要编辑的名言的id进行验证
{
print '<form action="edit_quote1.php" method="post">';
print '<p>名言:<textarea name="quote" rows="5" cols="30"></textarea></p>';
print '<p>作者:<input type="text" name="source" /></p>';
print '<p>这是你最喜欢的吗?<input type="checkbox" name="favorite" value="yes" /></p>';
print '<input type="hidden" name="id" value="' . $_GET['id']. '" />';
print '<input type="submit" name="submit" value="更新" /> </form>';
$_mysqli->close();
}
else print '没有获取到id!';
@include('footer.html');
?>
删除:
<?php
ob_start();
include('header.html');
print '<body>';
include('mysql_connect.php');
if (isset($_GET['id'])&&is_numeric($_GET['id'])&&($_GET['id']>0))//对需要编辑的名言的id进行验证
{ $query="SELECT quote,source,favorite FROM quotes WHERE quote_id={$_GET['id']}";
if($r=mysqli_query($_mysqli,$query))
{ $query1="DELETE FROM quotes WHERE quote_id={$_GET['id']}";
mysqli_query($_mysqli,$query1);
print '删除成功!';
print '于3秒内返回管理员界面!';
mysqli_close($_mysqli);
header('refresh:3; url=welcome.php');
exit;
}
else {print '无法删除!';
print '于3秒内返回管理员界面!';
mysqli_close($_mysqli);
header('refresh:3; url=welcome.php');
exit; }
}
else print '没有获取到id!';
mysqli_close($_mysqli);
@include('footer.html');
?>
编辑网页链接的php文件:
<?php
ob_start();
include('header.html');
print '<body>';
include('mysql_connect.php');
if($_SERVER['REQUEST_METHOD']=='POST')
{ $query="UPDATE quotes SET quote='{$_POST['quote']}',source='{$_POST['source']}' WHERE quote_id={$_POST['id']}";
$result=mysqli_query($_mysqli,$query);
if(mysqli_connect_errno($result))
{ print '更新失败!';}
else {print '更新成功,页面将于3秒内跳转!';
$_mysqli->close();
header('refresh:3; url=welcome.php');//欢迎界面还没写
exit;}
}
else print "没提交表单!";
include('footer.html');
?>
mysql_connect.php
<?php
$_mysqli= new mysqli();
$_mysqli->connect('localhost','root','galgaddott');
$dbc=$_mysqli->select_db('shujuku1');
?>
登出和注销见上条博客。
待加上验证码!
本人新手,请大佬指点,谢谢!