简易电话本
时间:2008-02-27
来源:互联网
实在想不到能写点什么,就做了个简易在线电话本.
比较简洁150行代码.
演示地址: http://203.81.53.84/~wang/test/phone.php
数据库:
id: 联系人编号
name:联系人名称
phone: 电话号码
qq: QQ号码
six: 性别 0-男, 1-女
比较简洁150行代码.
演示地址: http://203.81.53.84/~wang/test/phone.php
数据库:
id: 联系人编号
name:联系人名称
phone: 电话号码
qq: QQ号码
six: 性别 0-男, 1-女
复制PHP内容到剪贴板
<?php
#数据库配置
$config['host'] = 'localhost';
$config['username'] = 'webtable';
$config['password'] = '******';
#连接数据库
mysql_connect($config['host'],$config['username'],$config['password']);
#使用数据库
mysql_select_db('wang_web');
#post数据处理
$search_arr = array("/ union /i","/ select /i","/ update /i","/ outfile /i","/ or /i");
$replace_arr = array(' union ',' select ',' update ',' outfile ',' or ');
$name = strip_sql($_POST['username']);
$phone = intval($_POST['phone'])==0?'':intval($_POST['phone']);
$qq = intval($_POST['qq'])==0?'':intval($_POST['qq']);
$six = intval($_POST['six']);
if($_GET['type'] == 'seach'){//搜索
$querys = mysql_query("
SELECT *
FROM ph_phonebook
WHERE
name LIKE '%{$name}%' and
phone LIKE '%{$phone}%' and
qq LIKE '%{$qq}%' and
six LIKE '%{$six}%'");
}elseif($_GET['type'] == 'adduser'){//添加
if(empty($name) || empty($phone)){
exit('联系人名称和电话不能为空<a href="phone.php">点击这里返回重写</a>');
}
mysql_query("
INSERT INTO ph_phonebook
SET name='{$name}', phone='{$phone}', qq='{$qq}', six='{$six}'");
mysql_close();
header("Location: phone.php");
}elseif($_GET['type'] == 'deluser'){//删除
$id = intval($_GET['id']);
mysql_query("DELETE FROM ph_phonebook WHERE id={$id}");
mysql_close();
header("Location: phone.php");
}else{
$querys = mysql_query('SELECT * FROM ph_phonebook');
}
function strip_sql($string){#过滤字符串(防止SQL语句注入)
global $search_arr,$replace_arr;
return is_array($string) ? array_map('strip_sql', $string) : preg_replace($search_arr, $replace_arr, $string);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" c />
<title>电话本</title>
</head>
<body>
<script language="javascript" type="text/javascript">
function seach(){
document.getElementById('win').action = '';
document.getElementById('win').action = './phone.php?type=seach';
document.getElementById('win').submit();
}
function adduser(){
document.getElementById('win').action = '';
document.getElementById('win').action = './phone.php?type=adduser';
document.getElementById('win').submit();
}
function deluser(id){
window.location.href='./phone.php?type=deluser&id='+id;
}
</script>
<table width="100%" height="100%" border="1" cellpadding="0" cellspacing="0">
<tr height="100px">
<td>
<form action="phone.php" method="post" id="win">
<table>
<tr>
<td>
名称:
<input type="text" name="username" maxlength="50" />
</td>
<td>
手机:
<input type="text" name="phone" maxlength="11" />
</td>
<td>
QQ:
<input type="text" name="qq" maxlength="9" />
</td>
<td>
性别:
<label for="six_man">
<input type="radio" name="six" id="six_man" value="0" checked="checked">男
</label>
<label for="six_woman">
<input type="radio" name="six" id="six_woman" value="1" />女
</label>
</td>
</tr>
<tr>
<td colspan="4" align="center">
<input type="button" value="添加" >
<input type="button" value="搜索" >
<input type="button" value="显示全部" >
<input type="reset" value="重新填写">
</td>
</tr>
</table>
</form>
</td>
</tr>
<tr height="520px">
<td valign="top">
<table border="1" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td>名字</td>
<td>电话</td>
<td>QQ</td>
<td>性别</td>
<td width="20px;"> </td>
</tr>
<?php
while($row = mysql_fetch_assoc($querys)){
echo "<tr>";
echo "<td>{$row['name']} </td>";
echo "<td>{$row['phone']} </td>";
echo "<td>{$row['qq']} </td>";
$six = $row['six'] == 0?'男':'女';
echo "<td>{$six} </td>";
echo "<td><input type='button' value='删除这个人' onclick='deluser({$row['id']})'></td>";
echo "</tr>";
}
?>
</table>
</td>
</tr>
</table>
</body>
</html>
[ 本帖最后由 wangyl 于 2008-2-27 16:05 编辑 ] PHP代码:
<?php
#数据库配置
$config['host'] = 'localhost';
$config['username'] = 'webtable';
$config['password'] = '******';
#连接数据库
mysql_connect($config['host'],$config['username'],$config['password']);
#使用数据库
mysql_select_db('wang_web');
#post数据处理
$search_arr = array("/ union /i","/ select /i","/ update /i","/ outfile /i","/ or /i");
$replace_arr = array(' union ',' select ',' update ',' outfile ',' or ');
$name = strip_sql($_POST['username']);
$phone = intval($_POST['phone'])==0?'':intval($_POST['phone']);
$qq = intval($_POST['qq'])==0?'':intval($_POST['qq']);
$six = intval($_POST['six']);
if($_GET['type'] == 'seach'){//搜索
$querys = mysql_query("
SELECT *
FROM ph_phonebook
WHERE
name LIKE '%{$name}%' and
phone LIKE '%{$phone}%' and
qq LIKE '%{$qq}%' and
six LIKE '%{$six}%'");
}elseif($_GET['type'] == 'adduser'){//添加
if(empty($name) || empty($phone)){
exit('联系人名称和电话不能为空<a href="phone.php">点击这里返回重写</a>');
}
mysql_query("
INSERT INTO ph_phonebook
SET name='{$name}', phone='{$phone}', qq='{$qq}', six='{$six}'");
mysql_close();
header("Location: phone.php");
}elseif($_GET['type'] == 'deluser'){//删除
$id = intval($_GET['id']);
mysql_query("DELETE FROM ph_phonebook WHERE id={$id}");
mysql_close();
header("Location: phone.php");
}else{
$querys = mysql_query('SELECT * FROM ph_phonebook');
}
function strip_sql($string){#过滤字符串(防止SQL语句注入)
global $search_arr,$replace_arr;
return is_array($string) ? array_map('strip_sql', $string) : preg_replace($search_arr, $replace_arr, $string);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" c />
<title>电话本</title>
</head>
<body>
<script language="javascript" type="text/javascript">
function seach(){
document.getElementById('win').action = '';
document.getElementById('win').action = './phone.php?type=seach';
document.getElementById('win').submit();
}
function adduser(){
document.getElementById('win').action = '';
document.getElementById('win').action = './phone.php?type=adduser';
document.getElementById('win').submit();
}
function deluser(id){
window.location.href='./phone.php?type=deluser&id='+id;
}
</script>
<table width="100%" height="100%" border="1" cellpadding="0" cellspacing="0">
<tr height="100px">
<td>
<form action="phone.php" method="post" id="win">
<table>
<tr>
<td>
名称:
<input type="text" name="username" maxlength="50" />
</td>
<td>
手机:
<input type="text" name="phone" maxlength="11" />
</td>
<td>
QQ:
<input type="text" name="qq" maxlength="9" />
</td>
<td>
性别:
<label for="six_man">
<input type="radio" name="six" id="six_man" value="0" checked="checked">男
</label>
<label for="six_woman">
<input type="radio" name="six" id="six_woman" value="1" />女
</label>
</td>
</tr>
<tr>
<td colspan="4" align="center">
<input type="button" value="添加" >
<input type="button" value="搜索" >
<input type="button" value="显示全部" >
<input type="reset" value="重新填写">
</td>
</tr>
</table>
</form>
</td>
</tr>
<tr height="520px">
<td valign="top">
<table border="1" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td>名字</td>
<td>电话</td>
<td>QQ</td>
<td>性别</td>
<td width="20px;"> </td>
</tr>
<?php
while($row = mysql_fetch_assoc($querys)){
echo "<tr>";
echo "<td>{$row['name']} </td>";
echo "<td>{$row['phone']} </td>";
echo "<td>{$row['qq']} </td>";
$six = $row['six'] == 0?'男':'女';
echo "<td>{$six} </td>";
echo "<td><input type='button' value='删除这个人' onclick='deluser({$row['id']})'></td>";
echo "</tr>";
}
?>
</table>
</td>
</tr>
</table>
</body>
</html>
作者: wangyl 发布时间: 2008-02-27
鼓励一下!!!


作者: luzhou 发布时间: 2008-02-27
电话的数据长度不够哦
作者: 111 发布时间: 2008-02-28
手机:
<input type="text" name="phone" maxlength="11" /> <<----这里改就是了,设定11位.
<input type="text" name="phone" maxlength="11" /> <<----这里改就是了,设定11位.
作者: wangyl 发布时间: 2008-02-28
读者应该学会举一反三。

作者: luzhou 发布时间: 2008-02-28
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28