今天晚上玩了玩php,做了个登录页面,纪念一下。。。
代码:
zhuce.php
<!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>
<style>
.aa{
font-size:20px;
font-family:"幼园";
color:blue;
text-align:center;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body background="www_php/5912802_141854021589_2.jpg">
<form id="form1" name="form1" method="post" action="index.php" >
<table width="400" height="371" border="0" align="center" bordercolor="#00FF00" >
<tr>
<td colspan="2"><div align="center"><font class="aa">注册个人信息</font></div></td>
</tr>
<tr>
<td width="123">学号:</td>
<td width="261"><input type="text" name="id" id="id" /></td>
</tr>
<tr>
<td height="34">姓名:</td>
<td><input type="text" name="name" id="name" /></td>
</tr>
<tr>
<td height="37">密码:</td>
<td><input type="password" name="Password" id="name" /></td>
</tr>
<tr>
<td>性别:</td>
<td>
<input name="sex" type="radio" value="男" checked="checked" />
男
<input name="sex" type="radio" value="女" />
女
</td>
</tr>
<tr>
<td>出生年月:</td>
<td><input type="text" name="birth" id="birth" /></td>
</tr>
<tr>
<td>所学专业:</td>
<td> <select name="major" id="major">
<option >计算机</option>
<option>软件工程</option>
<option>信息管理</option>
</select>
</td>
</tr>
<tr>
<td height="72">备注:</td>
<td><label>
<textarea name="bz" id="bz" cols="30" rows="5"></textarea>
</label></td>
</tr>
<tr>
<td>兴趣:</td>
<td>
<input type="checkbox" name="XQ[]" value="听音乐" />
听音乐
<input type="checkbox" name="XQ[]" value="看小说" />
看小说
<input type="checkbox" name="XQ[]" value="上网" />
上网
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="bt" id="bt" value="提交" />
<input type="reset" name="bt1" id="bt1" value="重置" /></td>
</tr>
</table>
</form>
</body>
</html>
connect.php
<!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" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<?php
function _open()
{
$link=mysql_connect('localhost','root','')or die('连不上服务器');
$query=mysql_select_db('db1',$link);
if($query) echo "连接成功";
else echo "连接失败";
mysql_query('set names utf8');
}
function _close()
{
mysql_close();
}
?>
</body>
</html>
index.php
<!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" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<?php
if(isset($_POST['bt']))
{
$id=$_POST['id'];
$name=$_POST['name'];
$password=$_POST['Password'];
$password=md5($password);
$sex=$_POST['sex'];
$brith=$_POST['birth'];
$major=$_POST['major'];
$bz=$_POST['bz'];
$XQ=$_POST['XQ'];
$s1=implode(',',$XQ);
include "../connect.php";
_open();
$sql="insert into Student values('$id','$name','$password','$sex','$brith','$major','$bz','$s1')";
if(mysql_query($sql)) echo "插入成功";
else echo"插入失败";
_close();
}
?>
</body>
</html>
php中include不用#号,,,,,