kaola4549 发表于 2017-3-31 08:27:44

php写一个简单的通讯录

  <html>
<head>
<title>添加通讯录</title>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body>
<div align="center">
<form action="addtx.php" name="txform" method=post>
<table border="1">
<tr>
<td>姓名:</td>
<td><input type="text" name="un"></td>
</tr>
<tr>
<td>手机:</td>
<td><input type="text" name="tel"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="addtxbtn" value="添加"></td>
</tr>
</table>
<?php
$con=mysql_connect('localhost','root','') or die('连接失败'.mysql_error());
mysql_select_db("tongxunlu");
//mysql_query("set names gb2312");//如果页面字符集设置为GB2312则需要加上这句
$username=($_POST['un']);
$phone=($_POST['tel']);
$addtx="insert into txinfo(username,phone) values ('$username','$phone')";
mysql_query($addtx);
?>
</form>

</div>
</body>
</html>

  <html>
<head>
<title>显示通讯录</title>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body>
<div align="center">
<?php
$con=mysql_connect('localhost','root','') or die('连接失败'.mysql_error());
mysql_select_db("tongxunlu");
//mysql_query("set names gb2312");
$showtx="select username,phone from txinfo order by id desc";
$result=mysql_query($showtx);
?>

<table border="1">
<?php
$num_rows=mysql_num_rows($result);
if($num_rows>0)
{
while($row=mysql_fetch_array($result,MYSQL_ASSOC))
{
?>
<tr>
<td>姓名</td>
<td><?php echo $row["username"]?></td>
</tr>
<tr>
<td>手机</td>
<td><?php echo $row["phone"]?></td>
</tr>
<?php }}?>
</table>
</div>
</body>
</html>
页: [1]
查看完整版本: php写一个简单的通讯录