首页 > 后端开发 > php教程 > 这段代码中echo怎么不执行呢,高手给支个招

这段代码中echo怎么不执行呢,高手给支个招

WBOY
发布: 2016-06-23 13:54:31
原创
1252 人浏览过

public function add(){		$this->lottory_record_db=M('Lottery_record');		$this->lottory_db=M('Lottery');		 if($_POST['action'] ==  'add' ){			$lid 				= $this->_post('lid');			$wechaid 			= $this->_post('wechaid');			//$data['sn']			= $this->_post('sncode');			$data['phone'] 		= $this->_post('tel');			//$data['prize']		= $this->_post('winprize');			$data['wecha_name'] = $this->_post('wxname');			//$data['time']		= time(); 			//$data['islottery']	= 1;			//$data['usenums']	= 1;						$rid=intval($this->_post('rid'));			if (!$rid){				$thisRecord=$this->lottory_record_db->where(array('lid'=>$lid,'wecha_id'=>$wechaid,'islottery'=>1))->find();				$rid=$thisRecord['id'];			}			$rollback = $this->lottory_record_db->where(array('lid'=>$lid,'wecha_id'=>$wechaid,'id'=>$rid))->save($data);			$record=$this->lottory_record_db->where(array('id'=>$rid))->find();			echo'{"success":1,"msg":"恭喜!尊敬的<font color=red>'.$data['wecha_name'].'</font>请您保持手机通畅!你的领奖序号:<font color=red>'.$record['sn'].'</font>"}';			exit;			}	}
登录后复制


回复讨论(解决方案)

if($_POST['action'] == 'add' ){
条件 $_POST['action'] == 'add' 不成立,所以 echo 不执行

var_dump($_POST['action']);//输出看看值是什么?确定条件成立?
登录后复制

var_dump($_POST['action']);

条件是成立的,$rollback = $this->lottory_record_db->where(array('lid'=>$lid,'wecha_id'=>$wechaid,'id'=>$rid))->save($data);这句代码也是执行了的,数据库中有数据

那你输出的只是一个 json 串,需要 js 代码去解析呀

是js代码解晰的问题?
下面这段代码在同一页面,却又能弹出提示
public function exchange(){
$this->lottory_record_db=M('Lottery_record');
$this->lottory_db=M('Lottery');
$this->lottory_pw_db=M('Lottery_pw');
 if(IS_POST){
  $Lottery_pw = $this->lottory_pw_db->where(array('dpassword'=>trim($_POST['parssword'])))->find();
       
  if ($Lottery_pw['dpassword'] != trim($this->_post('parssword'))){
  echo'{"success":0,"msg":"密码不正确"}';exit;
  }else {
  $data['sendtime'] = time(); 
  $data['sendstutas'] = 1;
                $data['dname'] = $Lottery_pw['dname'];
                $data['dpassword'] = $Lottery_pw['dpassword'];
  $this->lottory_record_db->where(array('id'=> intval($_POST['rid'])))->save($data);
  echo'{"success":1,"msg":"领取成功","changed":1}';
  }
}
}

是js代码解晰的问题?
下面这段代码在同一页面,却又能弹出提示
public function exchange(){
$this->lottory_record_db=M('Lottery_record');
$this->lottory_db=M('Lottery');
$this->lottory_pw_db=M('Lottery_pw');
 if(IS_POST){
  $Lottery_pw = $this->lottory_pw_db->where(array('dpassword'=>trim($_POST['parssword'])))->find();
       
  if ($Lottery_pw['dpassword'] != trim($this->_post('parssword'))){
  echo'{"success":0,"msg":"密码不正确"}';exit;
  }else {
  $data['sendtime'] = time(); 
  $data['sendstutas'] = 1;
                $data['dname'] = $Lottery_pw['dname'];
                $data['dpassword'] = $Lottery_pw['dpassword'];
  $this->lottory_record_db->where(array('id'=> intval($_POST['rid'])))->save($data);
  echo'{"success":1,"msg":"领取成功","changed":1}';
  }
}
}


js代码帖出来吧

document.writeln("

function alert(title)

你在那里调用的?

$("#save-btn").bind("click",
function() {
var btn  = $(this);
var tel  = $("#tel").val();

var wechaid = $("#wechaid").val();
var winprize  = $("#winprize").val();
var sncode  = $("#sncode").val();
var lid  = $("#lid").val();
//var RegPhone = /^([0-9]{11})?$/;
//var falg;
//falg = tel.value.search(RegPhone);
if (!tel) {
alert("请输入正确{pigcms:$lottery.renametel}");
return
}


var submitData = {
sncode  : sncode,
tel  : tel,

wechaid : wechaid,
winprize:winprize,
rid: {pigcms:$Coupon.rid},
lid  : lid,
action  : "add"
};
$.post('index.php?g=Wap&m=Coupon&a=add', submitData,
function(data) {
if (data.success == true) {
alert(data.msg);
window.location.href=location.href;
//$("#zjl").hide("slow");
return
} else { 
//alert('失败'+data);
return
}
},"json")
});

$("#save-btnn").bind("click",
function () {
var submitData = {
id: {pigcms:$lottery.id},
rid: {pigcms:$Coupon.rid},
parssword: $("#parssword").val()
};
$.post('index.php?g=Wap&m=Coupon&a=exchange', submitData,
function (data) {
if (data.success == true) {
alert(data.msg);
if (data.changed == true) {
window.location.href = location.href;
}
return
} else {alert(data.msg);}
},
"json")
});

有报错误么。

$record=$this->lottory_record_db->where(array('id'=>$rid))->find();   看看这条语句有没有出错呢。

没有哦,这条语句支掉,再把下面改成如下,还是弹不出来

echo'{"success":1,"msg":"恭喜"}';
            exit;    
        }

if ($Lottery_pw['dpassword'] != trim($this->_post('parssword'))){
   echo'{"success":0,"msg":"密码不正确"}';exit;
   }else {
   $data['sendtime'] = time(); 
   $data['sendstutas'] = 1;
                 $data['dname'] = $Lottery_pw['dname'];
                 $data['dpassword'] = $Lottery_pw['dpassword'];
   $this->lottory_record_db->where(array('id'=> intval($_POST['rid'])))->save($data);
   echo'{"success":1,"msg":"领取成功","changed":1}';
   }
 }
 }

昨晚又测试,发现密码错误的时候会提示,输入正确的时候不提示

如果你确认有进入,那说明上面有代码发生致命错误,停止了。放出错误信息看看。

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板