祝大家新年快乐!新年新气象!

简易电话本

上一篇 / 下一篇  2008-02-27 16:06:54 / 个人分类:php

查看( 1133 ) / 评论( 4 )
实在想不到能写点什么,就做了个简易在线电话本.PHPChina 开源社区门户)^ R\MV?N#u
比较简洁150行代码.PHPChina 开源社区门户Dgv8Q5d&|3E
演示地址:http://203.81.53.84/~wang/test/phone.php
:l1R({4K"uM0数据库:PHPChina 开源社区门户r_qD*d
id:  联系人编号PHPChina 开源社区门户?p+W@*p
name:联系人名称PHPChina 开源社区门户(Y[(_\/ae9dK3E
phone: 电话号码PHPChina 开源社区门户mXZ`P` J8q(M
qq: QQ号码
m0g9U`kpl(Z]l0six: 性别 0-男, 1-女PHPChina 开源社区门户&_zxxQ9c{;BQM m
PHPChina 开源社区门户;u_D7C w9U7Z
<?phpPHPChina 开源社区门户%YUj"^$u~2h n CM
#数据库配置
d-r-DI6bts[I0D0
$config['host'] = 'localhost';
"^ u n*i*}}f*{0
$config['username'] = 'webtable';PHPChina 开源社区门户-tF ~A;\2^.cb5S(f
$config['password'] = '******';
zG5iYx#a!H_ T0
#连接数据库
a/H|Y"mM _tm0
mysql_connect($config['host'],$config['username'],$config['password']);
T2]@ N#k1UV0
#使用数据库PHPChina 开源社区门户D"w1]S{
mysql_select_db('wang_web');PHPChina 开源社区门户B9^!C LT p3AuFwo

~ hcpVG5N6vl0
#post数据处理
;D7{a8F'h*n`0
$search_arr = array("/ union /i","/ select /i","/ update /i","/ outfile /i","/ or /i");
'F|qX.x{r^)d:~0
$replace_arr = array(' union ',' select ',' update ',' outfile ',' or ');
2E&W+m dE5Sxa0
n5@)~]6l8WL(G;Q0
$name strip_sql($_POST['username']);PHPChina 开源社区门户P.@+l b4kz m
$phone intval($_POST['phone'])==0?'':intval($_POST['phone']);PHPChina 开源社区门户y X2lZ Z8[)k
$qq intval($_POST['qq'])==0?'':intval($_POST['qq']);
w!d+P:`F"SO,N0
$six intval($_POST['six']);
f i]#O-\ p(qjy$H0
gA?i wR5l C R0if(
$_GET['type'] == 'seach'){//搜索PHPChina 开源社区门户 umIQz6B}
PHPChina 开源社区门户a:zl"A.C,IUT:j
    
$querys mysql_query("PHPChina 开源社区门户5D Sey:n,B9i
            SELECT *
9cAKer0                FROM ph_phonebookPHPChina 开源社区门户A Xu KO9z[+Z0sz.E
                WHERE
;qb xF&RXt0                     name  LIKE '%{$name}%' andPHPChina 开源社区门户^U.?T.@;S|7T
                     phone  LIKE '%{$phone}%' andPHPChina 开源社区门户 z]n n6v2z4F
                     qq  LIKE '%{$qq}%' andPHPChina 开源社区门户y\TO2B9]#s
                     six  LIKE '%{$six}%'"
);PHPChina 开源社区门户AE]%{6H/x-V w

*ly"pxh lF1|0}elseif(
$_GET['type'] == 'adduser'){//添加
I5OAwJ,_'\ v(i D0    
if(empty($name) || empty($phone)){
5F;YQiXD#l0        exit(
'联系人名称和电话不能为空<a href="phone.php">点击这里返回重写</a>');
8f'_J ^"G4oy0    }PHPChina 开源社区门户r9NH*d;O
    
mysql_query("
`J%N5K Q6r0            INSERT INTO  ph_phonebook 
i W3M3u%D$ix9Gd&hQ6v0            SET name='{$name}', phone='{$phone}', qq='{$qq}', six='{$six}'"
);
2x+To-O8pOvxMO3d0    
mysql_close();
D&j5JP cFDhh*`0    
header("Location: phone.php");
'\+K(E;eb~R!j M0
.Mb%v J#yK_0}elseif(
$_GET['type'] == 'deluser'){//删除
s&wa#} n0    
$id intval($_GET['id']);PHPChina 开源社区门户ci*L1bM-A
    
mysql_query("DELETE FROM ph_phonebook WHERE id={$id}");PHPChina 开源社区门户,U\#{'`Ck,_svF,h
    
mysql_close();PHPChina 开源社区门户m5`G7eR5u1x0Y
    
header("Location: phone.php");
)C{7W1jDMU0}else{
v$WQ I$km*U5u0    
$querys mysql_query('SELECT * FROM ph_phonebook');
h5L H {a5` ^0}PHPChina 开源社区门户 {,l3le`
PHPChina 开源社区门户$Ci\ m$^I;@%VzH
function 
strip_sql($string){#过滤字符串(防止SQL语句注入)PHPChina 开源社区门户OR0DqJmZ4q
    
global $search_arr,$replace_arr;
"|[brg0    return 
is_array($string) ? array_map('strip_sql'$string) : preg_replace($search_arr$replace_arr$string);
Z^1K4Y*]?1Fa0}PHPChina 开源社区门户 ]%u8]P&W YT'b!Z
?>PHPChina 开源社区门户6D Oy X+O|ic|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">PHPChina 开源社区门户:Pa!F/xl"W
<html xmlns="http://www.w3.org/1999/xhtml">PHPChina 开源社区门户)E(J+]q b5F(x
<head>PHPChina 开源社区门户Cz}$]V{ t
<meta http-equiv="Content-Type" c />
%H+d]@K~j }H;s0<title>电话本</title>
ber1lg;pB&b2G v0</head>PHPChina 开源社区门户R V0IBT"h)I%D5j({+}
<body>
Ucv Dc%j0<scrīpt language="javascrīpt" type="text/javascrīpt">PHPChina 开源社区门户sr9V5x(w yu:?Z
    function seach(){
'G Q!_!U*Z5]1z0        document.getElementById('win').action = '';PHPChina 开源社区门户gGOw:Cd^tZs
        document.getElementById('win').action =  './phone.php?type=seach';PHPChina 开源社区门户 v [9gA}jH
        document.getElementById('win').submit();PHPChina 开源社区门户~H:N'roJS,P!N
    }PHPChina 开源社区门户~7X1| PKk'xt&C
    function adduser(){PHPChina 开源社区门户`Mi}e
        document.getElementById('win').action = '';PHPChina 开源社区门户*^Wcq(M8r4KbeN#] Od
        document.getElementById('win').action =  './phone.php?type=adduser';
'Q&CV!v6h qy+d0        document.getElementById('win').submit();    
T7u9_mM-{7L&S9G/o0    }PHPChina 开源社区门户7p%W6HU#x f0U h^
    function deluser(id){
4xvPFQ"F0        window.location.href='./phone.php?type=deluser&id='+id;PHPChina 开源社区门户+p#A9xz,l
    }
E6?!n'N(t(K S0</scrīpt>PHPChina 开源社区门户(C;g0lK@ K
<table width="100%" height="100%" border="1" cellpadding="0" cellspacing="0">
e2n)} u-Y4u_0    <tr height="100px">
'Z0c't(b0~$x/d:t0        <td>
M kL4b1?G%uW0            <form action="phone.php" method="post" id="win">
b8oIMf;c[M2r0            <table>PHPChina 开源社区门户`-O3i"IL^n4W G2n6z(X
                <tr>
R Dt {*UN0                    <td>
+}SGSU0                        名称:
)ea/_HI0b7DsI0                        <input type="text" name="username" maxlength="50" />PHPChina 开源社区门户hj I8FFsYY
                    </td>PHPChina 开源社区门户'Y$b7Gn1c
                    <td>PHPChina 开源社区门户6?7l"V x)l~M%KD?0kM
                        手机:PHPChina 开源社区门户6^bs1V Hvs
                        <input type="text" name="phone" maxlength="11" />
*n _#x^T? Hs+^0                    </td>PHPChina 开源社区门户7n!^ izHuA5a^+]
                    <td>
ZFF1@9dTd K0                        QQ:
T5L*z8I0|nRS0                        <input type="text" name="qq" maxlength="9" />PHPChina 开源社区门户 t g b7nJ
                    </td>
|!i-f\/|z3}0                    <td>PHPChina 开源社区门户:C&] Ph\HIx
                        性别:PHPChina 开源社区门户8q*bIh0U2U(i'A%V
                        <label for="six_man">
4Q4V i;_0Sip g0                        <input type="radio" name="six" id="six_man"  value="0" checked="checked">男PHPChina 开源社区门户 bH"H/f"Mm8Xxg
                        </label>
e+y3hv/vrohQ{"d0                        <label for="six_woman">
qoy*oG|0                        <input type="radio" name="six" id="six_woman" value="1" />女PHPChina 开源社区门户%]6F~TC,nE3d({IYQ
                        </label>PHPChina 开源社区门户;H.t{ IM,C3s{iq&Ec
                    </td>
-q#WdpesYE,[0                </tr>PHPChina 开源社区门户*s)~,d&s1A5k.r
                <tr>
7@z|k0Rp?T} sn0                    <td colspan="4" align="center">PHPChina 开源社区门户d;A'i#h#Na
                        <input type="button" value="添加" >
} Z/nMj0                        <input type="button" value="搜索" >
c:g'y%?Q0                        <input type="button" value="显示全部" >PHPChina 开源社区门户tWYl-|6IMQ$[
                        <input type="reset" value="重新填写">
(P I]M?#?0                    </td>
*OK6qq*W0                </tr>            
[Ql)h)U G0            </table>
qvJ'hU L-v0            </form>
bo:O,} w f |0        </td>
:x \9|.{F0    </tr>PHPChina 开源社区门户:w8N(t+z]U)])d
    <tr height="520px">PHPChina 开源社区门户,UIg4Z!o){u @"Ak
        <td valign="top">
|A}$^vf-IA"h0            <table border="1"  cellpadding="0" cellspacing="0" width="100%">PHPChina 开源社区门户1f8@Y1k4U{!s xD
                <tr>PHPChina 开源社区门户V wZ.L ~9F3U
                <td>名字</td>PHPChina 开源社区门户 UcO1C1Hxw
                <td>电话</td>PHPChina 开源社区门户 q bs7ie6ir%h.\
                <td>QQ</td>
pOc)g{E0                <td>性别</td>PHPChina 开源社区门户 ~n6J p$@
                <td width="20px;"> </td>
Y;DG-r,C @_ T N0                </tr>
zMPX E3am0<?php
g6k[T5x0                
while($row mysql_fetch_assoc($querys)){PHPChina 开源社区门户R.m{$|ehp[
                echo 
"<tr>";
k!Fq0H.m-Da&];K0                    echo 
"<td>{$row['name']} </td>";
|,u&R5LjeCR,\0                    echo 
"<td>{$row['phone']} </td>";PHPChina 开源社区门户7A(U6y!u D U;B
                    echo 
"<td>{$row['qq']} </td>";
gIM3c7{*|!X0                    
$six $row['six'] == 0?'男':'女';
X'C:^)t~kJ)ll0                    echo 
"<td>{$six} </td>";
x6t;I9] L.^6R0                    echo 
"<td><input type='button' value='删除这个人' onclick='deluser({$row['id']})'></td>";PHPChina 开源社区门户I4qI#aRz(@
                echo 
"</tr>";PHPChina 开源社区门户N+d"]2zEP;b
                }PHPChina 开源社区门户dK9z6s'W3a
?>
M+u;@&oFeV0
            </table>            
9J7a5] X2PHR0        </td>PHPChina 开源社区门户h PD q J
    </tr>PHPChina 开源社区门户9{i3r6k.g3Oy:mV
</table>PHPChina 开源社区门户 {fLJ gh9H
</body>
MVUc#h/r0</html>
PHPChina 开源社区门户 |f4wGDX$F%r
PHPChina 开源社区门户_dGS(rqZ

TAG: PHP php

luzhou(浅玉)的空间 luzhou 发布于2008-02-27 16:27:23
鼓励一下!!!
&c[:A/QYt/hPhp China|php论坛|php教程|php mysql|php源码|php安装|php手册|php学习|zend|Zend中国|PHPChina
稻草人个人空间 111 发布于2008-02-28 18:25:06
电话的数据长度不够哦
Lni_wang的PHP技术Blog wangyl 发布于2008-02-28 18:51:55
手机:
\GbK&g"q<input type="text" name="phone" maxlength="11" />  <<----这里改就是了,设定11位.
luzhou(浅玉)的空间 luzhou 发布于2008-02-28 19:21:22
回复 4# 的帖子
读者应该学会举一反三。PHPChina|php论坛|Zend中国8jV,h$U)f.D

我来说两句

(可选)

数据统计

  • 访问量: 10080
  • 日志数: 51
  • 图片数: 3
  • 书签数: 3
  • 建立时间: 2007-02-07
  • 更新时间: 2008-02-27

RSS订阅

Open Toolbar