$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); ?>
$result=mysql_query("select datediff($new_signin_time,signin_time) as diffdate where stu_id=$stu_id"); 怎么没有 from?
$sql_date_diff="select datediff('$new_signin_time','$signin_time') as diffdate";
这行之前都没变量$signin_time,没报错?还是你屏蔽了?另外,能不交给SQL来运算的,就别让SQL来运算。你直接读取最后一次签到时间,然后再跟现在的时间对比,大于一定的时间就去更新签到数据,然后输出成功信息,否则就给出失败的提示。
$signin_time 是我从sql中读出来的 最近签到时间 我这么执行 主要就是想用那个很方便的diffdate函数,因为可以返回相差多少天,我就很容易知道签到情况,请问这样为什么从不执行SQL语句,就是执行结果即便显示我断签但是今天签到了,数据库里的数据也没有改变(包括连续天数和最近签到时间)
2、$sql_date_diff="select datediff('$new_signin_time','$signin_time') as diffdate"; 中
$new_signin_time,$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);
$diffdate 是数组
你至少需要 $diffdate = $diffdate[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);
?>
怎么没有 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语句却没被执行 ,为什么呢
where stu_id=$stu_id");