<?php |
header( "content-type:text/html;charset=utf-8" ); |
//开启session |
session_start(); |
|
|
|
//接收表单传递的用户名和密码 |
$name = $_POST [ 'username' ]; |
$pwd = $_POST [ 'password' ]; |
|
|
//通过php连接到mysql数据库 |
$conn =mysql_connect( "localhost" , "" , "" ); |
|
//选择数据库 |
mysql_select_db( "test" ); |
//设置客户端和连接字符集 |
mysql_query( "set names utf8" ); |
//通过php进行insert操作 |
$sqlinsert = "insert into t1(username,password) values('{$name}','{$pwd}')" ; |
//通过php进行select操作 |
$sqlselect = "select * from t1 order by id" ; |
//添加用户信息到数据库 |
mysql_query( $sqlinsert ); |
|
//返回用户信息字符集 |
$result =mysql_query( $sqlselect ); |
|
echo "<h1>USER INFORMATION</h1>" ; |
echo "<hr>" ; |
echo "<table width='700px' border='1px'>" ; |
//从结果中拿出一行 |
echo "<tr>" ; |
echo "<th>ID</th><th>USERNAME</th><th>PASSWORD</th>" ; |
echo "</tr>" ; |
while ( $row =mysql_fetch_assoc( $result )){ |
echo "<tr>" ; |
//打印出$row这一行 |
echo "<td>{$row['id']}</td><td>{$row['username']}</td><td>{$row['password']}</td>" ; |
|
echo "</tr>" ; |
} |
echo "</table>" ; |
//释放连接资源 |
mysql_close( $conn ); |
|
} |
} |
?> |
初级程序员
by: 云代码会员 发表于:2016-08-26 10:11:46 顶(0) | 踩(0) 回复
110
回复评论