案例内有2个功能

时间:2018-05-17 19:35:52

标签: php sql pdo

我试图在php中添加2个函数。

我有2张桌子

  • Orcamento
  • Trabalho

当我点击一个按钮时,一条记录从orcamento转到trabalho,但记录仍然留在orcamento上,有没有办法删除它?我将我的代码粘贴到

下面
 case "aceitar_o": {

    $stmt = $conn->prepare("INSERT INTO trabalho (user, NomeCliente, mail, Telefone, descricao, estado) VALUES (:user, :NomeCliente, :mail, :Telefone, :descricao, 'Aprovado')");
    $stmt->bindParam(':user', $user);
    $stmt->bindParam(':NomeCliente', $NomeCliente);
    $stmt->bindParam(':mail', $mail);
    $stmt->bindParam(':Telefone', $Telefone);
    $stmt->bindParam(':descricao', $descricao);
    $stmt->bindParam(':estado', $estado);

    break;

}

是否可以在"之下添加另一个功能?打破; " ?

1 个答案:

答案 0 :(得分:0)

不,您无法在break之后执行任何操作。

  

break结束当前for,foreach,while,do-while或switch结构的执行。

- http://php.net/manual/en/control-structures.break.php

你可以制作2个函数并将它们放在case

case "aceitar_o": {
     $values = array('user' => $user, 'nome' => $NomeCliente, 'mail' => $mail, 'fone' => $Telefone, 'descri' => $descricao, 'estado' =>$estado);
     update($conn, $values);
     delete($conn, $values);
break;
....
function update($conn, $params) {
      $stmt = $conn->prepare("INSERT INTO trabalho (user, NomeCliente, mail, Telefone, descricao, estado) VALUES (:user, :NomeCliente, :mail, :Telefone, :descricao, 'Aprovado')");
      $stmt->bindParam(':user', $params['user']);
      $stmt->bindParam(':NomeCliente', $params['nome']);
      $stmt->bindParam(':mail', $params['mail']);
      $stmt->bindParam(':Telefone', $params['fone']);
      $stmt->bindParam(':descricao', $params['descric']);
      $stmt->execute(); // or you could just pass the $values to the execute if you name the index the same as the placeholders
}

此外,您没有名为estado的占位符。在您当前的查询中,它是一个静态值。