上面为添加页面效果图
header("content-type:text/html;charset=utf-8"); #链接数据库 $con=mysqli_connect('127.0.0.1','root','root','test') or die(mysqli_errno()); #查询sql语句 $sql="select * from student"; //查询所有学生信息 展示 $res=mysqli_query($con,$sql); while($arr=mysqli_fetch_assoc($res)){ $data[]=$arr; }
#循环处理时间 foreach($data as $k =>$v){ $data[$k]['stu_time']=date('Y-m-d '); $data[$k]['utime']=date('Y-m-d '); }
以上为添加页面数据代码
$arr=$_POST; #从添加页面接到的值 $connect=mysqli_connect('127.0.0.1','root','root','test');#链接数据库
//处理数组得到值 $n=count($arr['stu_num']); for($i=0;$i<$n;$i++){ $new[$i]['stu_id']=$arr['id'][$i]; $new[$i]['stu_num']=$arr['stu_num'][$i]; }
//循环添加 foreach($new as $k=>$v){ $stu_id=$v['stu_id']; $stu_num=$v['stu_num']; if($stu_num){#判断数组中是否有值是为0的 防止用户不添加 而值默认为0 此为正常验证 if(is_numeric($stu_num)){ $sql="insert into grade(stu_id,stu_num) values('$stu_id','$stu_num')"; $res=mysqli_query($connect,$sql); }else{ echo "请输入正确的数值 "; } } }
以上为执行添加的代码
上为展示页面的效果图
$('#btn').on('click',function(){ #添加一个点击事件 var txt=$('#sel_name').val(); var sign=$('#sign').val(); var score=$('#sel_score').val();#获取到搜索的三个值 $.ajax({ url:'student_list_select.php', type:'post', data:{txt:txt,sign:sign,score:score},#发送一个ajax请求 把获取到的值传过去 }).done(function(json_info){#回调函数 var ppj = JSON.parse(json_info); var str=""; for( var i in ppj){ str+="<tr>"+ "<td>"+ppj[i]['id']+"</td>"+#拼串 "<td>"+ppj[i]['stu_name']+"</td>"+ "<td>"+ppj[i]['stu_sex']+"</td>"+ "<td>"+ppj[i]['stu_age']+"</td>"+ "<td>"+ppj[i]['stu_num']+"</td>"+ "</tr>" } $('#boy').html(str);#找到需要替换数据的ID 把查询到的新的数据替换 }) })
上面为 展示的页面的搜索的javasrcipt 代码 主要为ajax部分
#接值 $txt=$_POST['txt']; $sign=$_POST['sign']; $score=$_POST['score']; if(!empty($txt)){ #判断关键字是否为空 $sql="select * from student join grade on grade.stu_id=student.id where stu_name like '%$txt%' ";#不为空 查询时加上根据关键字查询的条件 } if(!empty($sign)&&!empty($score)){#判断 < = > 分数是否为空 不为空的话 查询时加上 根据分数</>/=的条件 $sql="select * from student join grade on grade.stu_id=student.id where stu_num $sign$score"; } if(!empty($txt)&&!empty($sign)&&!empty($score)){#判断关键字 </>/= 分数 是否为空 不为空的话 查询时加上 关键字和分数 用and查询 $sql="select * from student join grade grade.stu_id=student.id where stu_name like '%$txt%' and stu_num $sign$score"; } $res=mysqli_query($con,$sql); while($arr=mysqli_fetch_assoc($res)){ $data[]=$arr; } echo json_encode($data);#返回一个json字符串
$('#email').on('click',function(){#点击发送邮件按钮时触发这个函数 var email $('#amil').val();#获取邮件 $.ajax({ url:"student_email.php",#发送一个ajax请求 type:'post', data:{email:email},#把邮件的值发送出去 }).done(function(info){ if(info==1000){ alert('发送成功');#发送成功提示发送成功 }else{ alert('发送失败');#发送失败提示发送失败 } }) })
以上是展示页面的javascript一个点击事件
页面空白 连接数据库的时候IP是127.0.0.1 数据库查不出数据 代码不运行 把ID换成localhost
邮件发不出去 关闭IPtables防火墙 或 firewalld 在运行一遍 如果还发不出去 在关闭selinux 临时关闭
- vi /etc/selinux/config
- #SELINUX=enforcing #注释掉
- SELINUX=disabled #增加
- :wq! #保存退出
- setenforce 0 #使配置立即生效