最近学了一点关于PHP和数据库的东西,
index.php文件
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style type="text/css">
body {
text-align: center;
padding-top: 150px;
}
p {
text-align: center;
}
</style>
</head>
<body>
<h1>学生签到</h1>
<hr>
<form action="s_inform.php" method="post">
学号:
<input type="text" name="Sno"/><br/><br/>
密码:
<input type="password" name="password"/><br/><br/>
时间:
<input type="datetime" name="time"/><br/><br/>
地点:
<input type="text" name="place" /><br/><br/>
<br />
<input type="submit" name="sub_infrom" value="签到">
<input type="button" name="button1" value="历史签到" onclick="window.location='qwe.php';">
<input type="button" name="button2" value="注册" onclick="window.location='register.php';">
</form>
<p><a href="serve.html">@有问题联系我们</a></p>
</body>
</html>
register.php文件
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style type="text/css">
body {
text-align: center;
padding-top: 150px;
}
p {
text-align: center;
}
body h2 {
text-align: left;
padding-left: 480px;
font-size: 18px;
}
</style>
</head>
<body>
<h1>学生签到</h1>
<hr>
<h2>+注册新用户</h2>
<form action="s_reg.php" method="post">
学号:
<input type="text" name="username" /><br/><br/>
密码:
<input type="password" name="password" /><br/><br/>
确认密码:
<input type="password" name="confirm" /><br/>
<br />
<input type="submit" name="reg" value="点击注册">
</form>
<p>@有问题联系我们</p>
</body>
</html>
inform.php文件
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
<?php
$user = $_POST["Sno"];
$psw = $_POST["password"];
$time = $_POST["time"];
$place = $_POST["place"];
if($user == "" || $psw == "" || $place == "" || $time=="")
{
echo "<script>alert('请确认信息完整性!'); history.go(-1);</script>";
}
else
{
mysql_connect("ip","root","密码"); //连接数据库
mysql_select_db("qiandao"); //选择数据库
mysql_query("set names utf8");//设置编码格式集
$sql = "select Sno from S_reg where Sno = '$user'"; //SQL语句
$result = mysql_query($sql); //执行SQL语句
$num = mysql_num_rows($result); //统计执行结果影响的行数
if($num==0) //如果未存在该用户
{
echo "<script>alert('该学号未注册'); history.go(-1);</script>";
}
else //存在当前注册用户名称
{
$sql_1 = "select password from S_reg where Sno = '$user' and password = '$psw'"; //SQL语句
$result_1 = mysql_query($sql_1); //执行SQL语句
$num_1 = mysql_num_rows($result_1); //统计执行结果影响的行数
if($num_1==0) //如果密码错误
{
echo "<script>alert('密码错误'); history.go(-1);</script>";
}
else
{
$sql_in = "insert into S_infrom (Sno,Place_qiandao,Time_qiandao) values ('$user','$place','$time')";
$res_in = mysql_query($sql_in);
//$num_insert = mysql_num_rows($res_insert);
if($res_in)
{
echo "<script>alert('签到成功!'); history.go(-1);</script>";
}
else
{
echo "<script>alert('系统繁忙,请稍候!'); history.go(-1);</script>";
}
}
}
}
?>
</body>
</html>
s_reg.php文件
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
<?php
//if(isset($_POST["Submit"]) && $_POST["Submit"] == "注册")
//{
$user = $_POST["username"];
$psw = $_POST["password"];
$psw_confirm = $_POST["confirm"];
if($user == "" || $psw == "" || $psw_confirm == "")
{
echo "<script>alert('请确认信息完整性!'); history.go(-1);</script>";
}
else
{
if($psw == $psw_confirm)
{
mysql_connect("ip","root","密码"); //连接数据库
mysql_select_db("qiandao"); //选择数据库
mysql_query("set names utf8");//设置编码格式集
$sql = "select Sno from S_reg where Sno = '$user'"; //SQL语句
$result = mysql_query($sql); //执行SQL语句
$num = mysql_num_rows($result); //统计执行结果影响的行数
if($num) //如果已经存在该用户
{
echo "<script>alert('该学号已注册'); history.go(-1);</script>";
}
else //不存在当前注册用户名称
{
$sql_insert = "insert into S_reg (Sno,password) values('$user','$psw')";
$res_insert = mysql_query($sql_insert);
//$num_insert = mysql_num_rows($res_insert);
if($res_insert)
{
echo "<script>alert('注册成功!'); history.go(-1);</script>";
}
else
{
echo "<script>alert('系统繁忙,请稍候!'); history.go(-1);</script>";
}
}
}
else
{
echo "<script>alert('密码不一致!'); history.go(-1);</script>";
}
}
/*}
else
{
echo "<script>alert('提交未成功!'); history.go(-1);</script>";
}*/
?>
</body>
</html>
qwe.php文件
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style type="text/css">
body {
text-align: center;
padding-top: 150px;
background-image: url(image/1.jpg);
}
</style>
</head>
<body>
<center>
<?php
$user = $_POST["username"];
$psw = $_POST["password"];
if($user == "" || $psw == "")
{
echo "<script>alert('请确认信息完整性!'); history.go(-1);</script>";
}
else
{
$con=mysql_connect("ip","root","密码"); //连接数据库
mysql_select_db("qiandao"); //选择数据库
mysql_query("set names utf8");//设置编码格式集
$sql = "select Sno from S_reg where Sno = '$user'"; //SQL语句
$result = mysql_query($sql); //执行SQL语句
$num = mysql_num_rows($result); //统计执行结果影响的行数
if($num==0) //如果未存在该用户
{
echo "<script>alert('该学号未注册'); history.go(-1);</script>";
mysql_close($con);
}
else //存在当前注册用户名称
{
$sql_1 = "select password from S_reg where Sno = '$user' and password = '$psw'"; //SQL语句
$result_1 = mysql_query($sql_1); //执行SQL语句
$num_1 = mysql_num_rows($result_1); //统计执行结果影响的行数
if($num_1==0) //如果密码错误
{
echo "<script>alert('密码错误'); history.go(-1);</script>";
mysql_close($con);
}
else
{
$q="select * from S_infrom where Sno='$user'";//设置查询指令
$result=mysql_query($q);//执行查询
echo "<table border='1'>
<tr>
<th>学号</th>
<th>签到地点</th>
<th>签到时间</th>
</tr>";
while($row=mysql_fetch_assoc($result))//将result结果集中查询结果取出一条
{
echo"<tr><td>".$row["Sno"]."</td>
<td>".$row["Place_qiandao"]."</td>
<td>".$row["Time_qiandao"]."</td></tr>";
}
echo "</table>";
}
}
}
?>
</center>
</body>
</html>