初级培训成果1--会员管理系统
上一篇 / 下一篇 2008-03-13 19:35:46 / 个人分类:PHP学习
REG.PHP
<html>
<head>
<title>会员注册</title>
<scrīpt language="javascrīpt">
function yz()
{
var user = document.getElementById('user').value;
var pwd = document.getElementById('pwd').value;
var email = document.getElementById('email').value.indexOf("@");
if(user.length == 0)
{
alert("请输入账号!");
return false; // 验证通过则返回 TURE ,不通过则返回 FALSE;
}else if(pwd.length == 0)
{
alert("请输入密码!");
return false ; // 验证通过则返回 TURE ,不通过则返回 FALSE;
}else if(email<0){
a = alert("请输入邮箱!");
return false;
}
return ture ; // 验证通过则返回 TURE ,不通过则返回 FALSE;
}
</scrīpt>
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#FF9966" vlink="#FF9966" alink="#FFCC99">
<form action="ok.php" method="POST" ōnsubmit="return yz();">
<div style="border:1px #3C5B7B dotted;width:300px;">
<div style="margin-left:50px;">
<div>
昵称:<input type="text" id="user" name="u9" />
</div>
<div>
密码:<input type="password" id="pwd" name="p9" />
</div>
<div>
E-Mail:<input type="text" id="email" name="e9" />
</div>
<div>
QQ:<input type="text" id="qq" name="q9" />
</div>
</div>
<div style="display:block;">
<div style="float:left;">
自我介绍:
</div>
<div style="float:left;">
<textarea cols="25" rows="10" id="js" name="j9" >这家伙很懒,什么也没留下.</textarea>
</div>
<div stylt="clear:both"></div>
</div>
<div>
<input type="submit" value="注册" />
<!-- onsubmit 时间决定是否提交表单! -->
</div>
</div>
</form>
</body>
</html>
======================== OK.PHP
<?php
include("conn.php");
$user = $_POST["u9"];
$pwd = $_POST["p9"];
$email = $_POST["e9"];
$qq = $_POST["q9"];
$content = $_POST["j9"];
$sql = "INSERT INTO g_users
SET
name='{$user}',
pwd = '{$pwd}',
email = '{$email}',
qq = '{$qq}',
myself = '{$content}' ";
$ok = mysql_query($sql);
if($ok){
echo "注册成功!<br />";
echo "<a href=\"login.php\">立即登入</a>";
}else{
echo "注册失败!<br />";
echo "<a href=\"reg.php\">返回</a>";
}
?>
==================== LOGIN.PHP
<?php
session_start();
$_SESSION['u'];
include("conn.php");
$op = $_POST["gu"];
$ow = $_POST["gpwd"];
if($ow)
{
$sql = "select pwd from g_users where pwd={$ow}";
$w = mysql_query($sql);
$rows = mysql_fetch_array($w);
if($ow == $rows[0])
{
$_SESSION['u'] = $op;
echo "<scrīpt>";
echo "window.localtion.href=\"http://localhost/users/uindex.php\";";
echo "</scrīpt>";
}else{
echo "<scrīpt>";
echo "alert(\"您还没有注册!\");";
echo "</scrīpt>";
}
}
if($_SESSION['u']){
echo "<scrīpt>";
echo "window.location.href=\"http://localhost/users/uindex.php\";";
echo "</scrīpt>";
}else{
echo <<<EOP
<html>
<head>
<title>会员登入</title>
<scrīpt>
function yz()
{
var u = document.getElementById('use').value;
var p = document.getElementById('ppwd').value;
if(u.length == 0)
{
alert("请输入用户名或密码!");
return false;
}else if(p.length == 0){
alert("请输入用户名或密码!");
return false;
}
return true;
}
function op()
{
window.location.href="reg.php";
}
</scrīpt>
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#FF9966" vlink="#FF9966" alink="#FFCC99">
<center>
<form action="login.php" method="POST" ōnsubmit="return yz();" >
<div style="border:1px #000000 dotted;width:500px;">
<div style="border-bottom:1px #000000 dotted;">
会员登入
</div>
<div style="border-bottom:1px #000000 dotted;">
<div>
用户名: <input type="text" name="gu" id="use" />
</div>
<div>
密码: <input type="password" name="gpwd" id="ppwd" />
</div>
</div>
<div >
<input type="submit" value="登入" />
<input type="button" value="注册" ōnclick="op();" />
</div>
</div>
</form>
</center>
</body>
</html>
EOP;
}
?>
================= UINDEX.PHP
<?php
session_start();
include("conn.php");
if($_SESSION['u'])
{
echo <<<EOP
<html>
<head>
<title>会员管理</title>
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#FF9966" vlink="#FF9966" alink="#FFCC99">
<table border="1" >
<thead>
<tr>
<th>昵称</th>
<th>E-Mail</th>
<th>QQ</th>
<th>自我介绍</th>
<th>管理</th>
</tr>
</thead>
<tbody>
EOP;
$sql = "select * from g_users";
$result = mysql_query($sql);
while($rows = mysql_fetch_array($result)){
echo <<<OK
<tr>
<td>{$rows[1]}</td>
<td>{$rows[2]}</td>
<td>{$rows[3]}</td>
<td>{$rows[4]}</td>
<td> <a href="del.php?id={$rows[0]}">删除</a> | <a href="edit.php?id={$rows[0]}">修改</a></td>
</tr>
OK;
}
echo <<<POE
</tbody>
</table>
</body>
</html>
POE;
}
?>
================== conn.php
<?php
CLASS OOP{
function conn(){
$a = "localhost";
$b = "root";
$c = "tqcom";
$conn = mysql_connect($a,$b,$c) or die("数据库连接失败!");
mysql_select_db("guestbook") or die("数据库选择失败!");
mysql_query("set names gbk")or die("数据库编码设置失败!");
}
function cx()
{
$this -> conn();
$sql = "select * from g_users";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { // MYSQL_ASSOC代表按字段取键名
$rows[] = $row;
}
return $rows;
}
}
$a = new OOP();
$a ->conn();
?>
============== del.php
<?php
session_start();
include("conn.php");
$byid = $_GET['id'];
if($_SESSION['u'])
{
$sql = "delete from g_users where id={$byid}";
$jg = mysql_query($sql);
$search = "select id from g_users where id={$byid}";
$j = mysql_query($search);
if($j)
{
echo "删除成功!<br />";
echo "<a href=\"uindex.php\">返回上一页</a>";
}else{
echo "删除失败";
echo "<a href=\"uindex.php\">返回上一页</a>";
}
}
?>
==================== edit.php
<?php
session_start();
include("conn.php");
$acquire = $_GET['id'];
$_SESSION['id'] = $acquire;
$sql = "select * from g_users where id={$acquire}";
$result = mysql_query($sql);
var_dump($result);
while($rows = mysql_fetch_array($result))
{
echo <<<OOP
<html>
<head>
<title>会员编辑</title>
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#FF9966" vlink="#FF9966" alink="#FFCC99">
<form action="gedit.php" method="POST" >
<div style="border:1px #000000 dotted;width:300px;">
<div style="margin-left:40px;">
<div style="border-bottom:1px #000000 dotted;">
昵称:<input type="text" value="{$rows[1]}" name="user" />
</div>
<div style="border-bottom:1px #000000 dotted;">
密码:<input type="password" value="{$rows[2]}" name="pwd" />
</div>
<div style="border-bottom:1px #000000 dotted;">
E-Mail:<input type="email" value="{$rows[3]}" name="email" />
</div>
<div style="border-bottom:1px #000000 dotted;">
QQ:<input type="text" value="{$rows[4]}" name="qq" />
</div>
</div>
<div style=" display:inline;">
<div style="float:left;">
自我介绍
</div>
<div style="float:left;">
<textarea cols="30" rows="10" name="js" >{$rows[5]}</textarea>
</div>
</div>
<div><input type="submit" value="保存" /></div>
</div>
</form>
</body>
<html>
OOP;
}
?>
================= 面向对象封装后的 class_uindex.php
<?php
session_start();
include("conn.php");
if($_SESSION['u'])
{
echo <<<EOP
<html>
<head>
<title>会员管理</title>
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#FF9966" vlink="#FF9966" alink="#FFCC99">
<table border="1" >
<thead>
<tr>
<th>昵称</th>
<th>E-Mail</th>
<th>QQ</th>
<th>自我介绍</th>
<th>管理</th>
</tr>
</thead>
<tbody>
EOP;
$b = new OOP();
$ba = $b->cx(); // 调用类中的查询语句
foreach ($ba as $value){
echo "<tr>";
echo "<td>".$value['name']."</td>";
echo "<td>".$value['email']."</td>";
echo "<td>".$value['qq']."</td>";
echo "<td>".$value['myself']."</td>";
echo "<td>"."<a href=\"del.php?id={$value['id']}\">删除</a> |"."<a href=\"edit.php?id={$value['id']}\">修改</a> |"."</td>";
echo "</tr>";
}
echo <<<POE
</tbody>
</table>
</body>
</html>
POE;
}
?>
===================== 以上只是一个小练习....其他的慢慢发,现在这里上网是一种奢求,所以赶快发上来了,有什么不好的地方请大家多指教.
相关阅读:
- 自己写的MySQL数据库类 (ares333, 2008-1-20)
- 批量缩略图 (caicaiphper, 2008-2-01)
- 项目考虑四部曲 (linmaogan, 2008-2-03)
- 理解PHP5中static和const关键字 (design_dd, 2008-2-21)
- PHP5中的this,self和parent关键字详解 (design_dd, 2008-2-21)
- PHP5面向对象的优点 (design_dd, 2008-2-22)
- PHP的环境配置 (小蜘蛛学习, 2008-2-23)
- 去掉制定的HTML标签 (zhangfan238, 2008-2-24)
- 去掉制定的HTML标签 (zhangfan238, 2008-2-24)
- 08.3.2 (ipengjun, 2008-3-03)
