当前位置:Gxlcms > PHP教程 > 这段代码中echo怎么不执行呢,高手给支个招

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

时间:2021-07-01 10:21:17 帮助过:4人阅读

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":"恭喜!尊敬的'.$data['wecha_name'].'请您保持手机通畅!你的领奖序号:'.$record['sn'].'"}';			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("