签到系统的php后台处理部分求解答

ITAS 2014-09-19 09:44:35
我想做的是点欢迎界面的按钮调用php后台处理数据,根据现在时间与数据库中上次签到时间的差值判断签到的情况。。但是现在就是即便可以判断,数据库也不按我的要求被修改。。。后面我会上其他页面的图片。。谢谢大家帮助我解答
<?php
$conn = odbc_connect("DRIVER={MySQL ODBC 5.2 Unicode Driver};
Server=localhost;Database=test","root","lzw0201");
$stu_id="12570219";//实际中由登陆表单获取;
//
$sql_select_time="select signin_time from signin where stu_id=$stu_id";
$sql_select_days="select con_days from signin where stu_id=$stu_id";
$sql_con_days="update signin set con_days=con_days+1,signin_time=$new_signin_time
where stu_id=$stu_id;";
$sql_signin_success="update signin set con_days=1,signin_time=$new_signin_time
where stu_id=$stu_id;";
$sql_date_diff="select datediff('$new_signin_time','$signin_time') as diffdate";
//
if (!$conn){
exit("Connection Failed: " . $conn);}
$rs=odbc_exec($conn,$sql_select_time);
while(odbc_fetch_row($rs))
{
$signin_time=odbc_result($rs,"signin_time");
//$con_days=odbc_result($rs,"con_days");
$new_signin_time=date("Y-m-d H:i:s",time());
$diffdate=mysql_query($sql_date_diff);
if($diffdate==0 or $diffdate<0){
header("Location:http://localhost:801/SignIn/noRepeat.html");
}else if($diffdate>0 and ($diffdate<1 or $diffdate==1)){
mysql_query($sql_con_days);
header("Location:http://localhost:801/SignIn/con_signinSuccess.php");
}else if($diffdate>1){
mysql_query($sql_signin_success);
header("Location:http://localhost:801/SignIn/signinSuccess.html");
}
}
odbc_close($conn);
?>
...全文
430 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
ITAS 2014-09-22
  • 打赏
  • 举报
回复
引用 14 楼 xuzuning 的回复:
mysql_query("update signin set con_days=1,signin_time='$new_signin_time' where stu_id=$stu_id");
嗯嗯 ,这个昨天没注意,最后才发现,谢谢您的帮助~~~
xuzuning 2014-09-22
  • 打赏
  • 举报
回复
mysql_query("update signin set con_days=1,signin_time='$new_signin_time' where stu_id=$stu_id");
xuzuning 2014-09-21
  • 打赏
  • 举报
回复
$diffdate=mysql_fetch_array($result); 后 $diffdate 是数组 你至少需要 $diffdate = $diffdate[0];
ITAS 2014-09-21
  • 打赏
  • 举报
回复
引用 6 楼 xuzuning 的回复:
1、你使用 odbc_connect 连接数据库, 怎么又使用 mysql_query 操作数据库? 2、$sql_date_diff="select datediff('$new_signin_time','$signin_time') as diffdate"; 中 $new_signin_time,$signin_time 未赋值
您好!我已经把odbc连接改为mysql连接了,$new_signin_time我去的是当前系统时间并且进行了日期格式的格式化 $new_signin_time=date("y-m-d h:i:s",time());signin_time是数据表俩原有的属性,所以$去掉了,直接用数据库表里面的值,现在这句话是这样写的 $result=mysql_query("select datediff('$new_signin_time',signin_time) as diffdate where stu_id=$stu_id"); $diffdate=mysql_fetch_array($result); 但是diffdate的返回值还是有问题,接下来的代码是这样的 if($diffdate==0){//不可重复签到 header("Location:http://localhost:801/SignIn/noRepeat.html"); }else if($diffdate==1){//连续签到 mysql_query("update signin set con_days=con_days+1,signin_time=$new_signin_time where stu_id=$stu_id"); header("Location:http://localhost:801/SignIn/con_signinSuccess.php"); }else if($diffdate>1){//断签但今日签到 mysql_query("update signin set con_days=1,signin_time=$new_signin_time where stu_id=$stu_id"); header("Location:http://localhost:801/SignIn/signinSuccess.html"); } mysql_close($con);
ITAS 2014-09-21
  • 打赏
  • 举报
回复
引用 10 楼 xuzuning 的回复:
$result=mysql_query("select datediff($new_signin_time,signin_time) as diffdate where stu_id=$stu_id"); 怎么没有 from
现在可以判断正确了,但是 else if($diffdate[0]>1){//断签但今日签到 mysql_query("update signin set con_days=1,signin_time=$new_signin_time where stu_id=$stu_id"); header("Location:http://localhost:801/SignIn/signinSuccess.html"); } 条件句里面的mysql_query语句却没被执行 ,为什么呢
ITAS 2014-09-21
  • 打赏
  • 举报
回复
引用 11 楼 u011575913 的回复:
[quote=引用 10 楼 xuzuning 的回复:] $result=mysql_query("select datediff($new_signin_time,signin_time) as diffdate where stu_id=$stu_id"); 怎么没有 from
因为不在数据表里面。。我也发现娶不到结果了。。我的表里面只有那三项。。好吧 我以为想计算的话就要用select形式,我从网上找到的。。。请问我从外面穿进去一个只和表里面的一个值进行datediff运算,返回datediff这个差值 应该怎么写。。。[/quote] 我调好了 谢谢您的帮助 居然烦了这么弱智的问题
ITAS 2014-09-21
  • 打赏
  • 举报
回复
引用 10 楼 xuzuning 的回复:
$result=mysql_query("select datediff($new_signin_time,signin_time) as diffdate where stu_id=$stu_id"); 怎么没有 from
因为不在数据表里面。。我也发现娶不到结果了。。我的表里面只有那三项。。好吧 我以为想计算的话就要用select形式,我从网上找到的。。。请问我从外面穿进去一个只和表里面的一个值进行datediff运算,返回datediff这个差值 应该怎么写。。。
xuzuning 2014-09-21
  • 打赏
  • 举报
回复
$result=mysql_query("select datediff($new_signin_time,signin_time) as diffdate where stu_id=$stu_id"); 怎么没有 from
ITAS 2014-09-21
  • 打赏
  • 举报
回复
引用 8 楼 xuzuning 的回复:
$diffdate=mysql_fetch_array($result); 后
$diffdate 是数组
你至少需要 $diffdate = $diffdate[0];

我按您说的,但是结果和之前一样,我现在的问题是我返回的结果总是不可重复签到,也就是说$diffdate[0]总是0,但是数据库里的数据不是这样的。。
这是现在的代码:
<?php
$con = mysql_connect("localhost","root","lzw0201");
if (!$con){
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test",$con);

$stu_id="12570219";//实际中由登陆表单获取;
$new_signin_time=date("y-m-d h:i:s");

$result=mysql_query("select datediff($new_signin_time,signin_time) as diffdate where stu_id=$stu_id");
$diffdate=mysql_fetch_array($result);
if($diffdate[0]==0){//不可重复签到
header("Location:http://localhost:801/SignIn/noRepeat.html");
}else if($diffdate[0]==1){//连续签到
mysql_query("update signin set con_days=con_days+1,signin_time=$new_signin_time
where stu_id=$stu_id");
header("Location:http://localhost:801/SignIn/con_signinSuccess.php");
}else if($diffdate[0]>1){//断签但今日签到
mysql_query("update signin set con_days=1,signin_time=$new_signin_time
where stu_id=$stu_id");
header("Location:http://localhost:801/SignIn/signinSuccess.html");
}

mysql_close($con);
?>

xuzuning 2014-09-20
  • 打赏
  • 举报
回复
1、你使用 odbc_connect 连接数据库, 怎么又使用 mysql_query 操作数据库? 2、$sql_date_diff="select datediff('$new_signin_time','$signin_time') as diffdate"; 中 $new_signin_time,$signin_time 未赋值
ITAS 2014-09-19
  • 打赏
  • 举报
回复
数据表里面存的是学号,连续签到天数,最近一次签到时间
ITAS 2014-09-19
  • 打赏
  • 举报
回复

这是欢迎界面

这是连续签到是跳出的页面,在这个页面中重新读取连续签到天数,展现给用户

这是我的表,时间什么的是我自己设定的
ITAS 2014-09-19
  • 打赏
  • 举报
回复

这就是上面代码的截图
ITAS 2014-09-19
  • 打赏
  • 举报
回复
引用 4 楼 Novolee 的回复:
先不说你的逻辑,光语法上就有错误 $sql_date_diff="select datediff('$new_signin_time','$signin_time') as diffdate"; 这行之前都没变量$signin_time,没报错?还是你屏蔽了? 另外,能不交给SQL来运算的,就别让SQL来运算。你直接读取最后一次签到时间,然后再跟现在的时间对比,大于一定的时间就去更新签到数据,然后输出成功信息,否则就给出失败的提示。
$signin_time 是我从sql中读出来的 最近签到时间 我这么执行 主要就是想用那个很方便的diffdate函数,因为可以返回相差多少天,我就很容易知道签到情况,请问这样为什么从不执行SQL语句,就是执行结果即便显示我断签但是今天签到了,数据库里的数据也没有改变(包括连续天数和最近签到时间)
李睿_Lee 2014-09-19
  • 打赏
  • 举报
回复
先不说你的逻辑,光语法上就有错误 $sql_date_diff="select datediff('$new_signin_time','$signin_time') as diffdate"; 这行之前都没变量$signin_time,没报错?还是你屏蔽了? 另外,能不交给SQL来运算的,就别让SQL来运算。你直接读取最后一次签到时间,然后再跟现在的时间对比,大于一定的时间就去更新签到数据,然后输出成功信息,否则就给出失败的提示。

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧