1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>sign</title> </head> <body> <center> <input type="text" name="username"> <button>签到</button><span id='span'></span> <div> <table id="box" border="1"></table> </div> </center> </body> </html> <script src="jquery.1.12.min.js"></script> <script> $(function(){ $('button').click(function(){ var username=$(':text').val(); $.ajax({ type:'post', url:'admin.php', data:{username:username}, dataType:'json', success:function(res){ if(res.success==1){ $('#span').html('签到成功'); var str='<tr><td>用户名</td><td>连续签到天数</td><td>总积分</td></tr>'; str+='<tr><td>'+res.msg.username+'</td><td>'+res.msg.count+'</td><td>'+res.msg.point+'</td></tr>'; $('#box').html(str); } } }) }); }) </script> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | <?php header('content-type:text/html;charset=utf-8'); $pdo=new PDO('mysql:host=localhost;dbname=databasename;','root','root'); $pdo->exec('set names utf8'); $username=$_POST['username']; $sqlQuery="select * from user where username='$username'"; $row=$pdo->query($sqlQuery)->fetch(PDO::FETCH_ASSOC); if($row){ $sign_time=$row['sign_time']; $sign_time=strtotime($sign_time); $int=date('Y-m-d'); $int=strtotime($int);//5 $ints=$int+86400; //6 $int_s=$int-86400; //4 //当天已签到 if($int<$sign_time&&$sign_time<$ints){ // echo '您已签到'; } //昨天未签到,积分,天数在签到修改为1 if($sign_time<$int_s){ $count=1; $point=1; $sign_time=date('Y-m-d H:s:i'); $sqlRow="update user set count='$count',point='$point',sign_time='$sign_time' where username='$username'"; $res=$pdo->exec($sqlRow); // echo '签到成功修改为1'; } //请签到 if($int_s<$sign_time&&$sign_time<$int){ $count=$row['count']+1; $point=$row['point']+1; $sign_time=date('Y-m-d H:s:i'); $sqlupdate="update user set count='$count',point='$point',sign_time='$sign_time' where username='$username'"; $res=$pdo->exec($sqlupdate); // echo '签到成功+1'; } }else{ $count=1; $point=1; $sign_time=date('Y-m-d H:s:i'); $sqlAdd="insert into user values (null,'$username','$count','$point','$sign_time')"; $res=$pdo->exec($sqlAdd); // echo '恭喜你签到成功----1'; } //////////////////////响应 $sqlEnd="select * from user where username='$username'"; $info=$pdo->query($sqlEnd)->fetch(PDO::FETCH_ASSOC); echo json_encode(array('success'=>1,'msg'=>$info));die; ?> |
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |