duanmu6231
2017-07-05 11:54
浏览 16
已采纳

为什么变量值未在插入查询中显示

I have this code snippet

$taskAssignedCompleteId = $row["TaskAssignCompletionId"];
echo "taskAssignedCompleteId::".$taskAssignedCompleteId. "
";

if($taskAssignedCompleteId == 0 || $taskAssignedCompleteId = null)
{
    echo "Currently no task assigned to you. If you are not doing a task on PMS and still receving this massage then, contact your team lead";
    return;
}

$sqlInsert = "INSERT INTO emp_task_finished_request (EmpTaskAssignCompletionId, RequestDateTime) VALUES (".$taskAssignedCompleteId.", '$date')";
echo "output : ".$sqlInsert;
$queryInsert = $connPDO->exec($sqlInsert);

    echo "
 output : ".$queryInsert;

Surprisingly $taskAssignedCompleteId value is not showing in query when i echo my $queryInsert varaiable while it is perfectly showing when i directly echo $taskAssignedCompleteId. Why is the problem? it is very strange for me. here is my output

taskAssignedCompleteId::13
sqlInsert full : INSERT INTO emp_task_finished_request (EmpTaskAssignCompletionId, RequestDateTime) VALUES (, '2017-07-05 16:53:45')
 output :

图片转代码服务由CSDN问答提供 功能建议

我有这段代码

  $ taskAssignedCompleteId = $ row  [“TaskAssignCompletionId”]; 
echo“taskAssignedCompleteId ::”。$ taskAssignedCompleteId。  “
”; 
 
if($ taskAssignedCompleteId == 0 || $ taskAssignedCompleteId = null)
 {
 echo“当前没有分配给您的任务。如果您没有在PMS上执行任务并仍然接受此按摩 然后,联系你的团队负责人“; 
 return; 
} 
 
 $ sqlInsert =”INSERT INTO emp_task_finished_request(EmpTaskAssignCompletionId,RequestDateTime)VALUES(“。$ taskAssignedCompleteId。”,“$ date”)“; 
echo” 输出:“。$ sqlInsert; 
 $ queryInsert = $ connPDO-> exec($ sqlInsert); 
 
 echo”
 output:“。$ queryInsert; 
   
  
 

令人惊讶的是,当我直接 $ taskAssignedCompleteId < /代码>。 为什么会出问题? 这对我来说很奇怪。 我的输出

  taskAssignedCompleteId :: 13 
sqlInsert full:INSERT INTO emp_task_finished_request(EmpTaskAssignCompletionId,RequestDateTime)VALUES(,'2017-07-  05 16:53:45')
输出:
   
 
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dongxi2163 2017-07-05 12:00
    已采纳

    You need to correct your if statement. $taskAssignedCompleteId = null is not correct. Kindly replace it by following

    if($taskAssignedCompleteId == 0 || $taskAssignedCompleteId == null)
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • dpziir0079 2017-07-05 11:58

    you should use == for comparison operator . = is assignment operator .so it's assigning null to $taskAssignedCompleteId variable .

    if($taskAssignedCompleteId == 0 || $taskAssignedCompleteId == null) { .. }
    
    评论
    解决 无用
    打赏 举报
  • donglu5041 2017-07-05 11:59

    Change $taskAssignedCompleteId = null to $taskAssignedCompleteId == null

    By doing this, you are assigning taskAssignedCompleteId to a null value. To compare use "==" but you already know that. Just a typo I guess.

    Darn, somebody beat me to the answer as I'm typing this.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题