PHP update undefine

-1

I can not do the Update in the database

faults.php

<?php
if($_SESSION['MM_Username']=="Comandante"){
    if(isset($_POST['estadoComando'])){
        updater($_POST['estadoComando'],$_POST['id']); //<-- linha 213
    }
    function updater($value,$id){
        // Create connection
        //$conn = new mysqli( 'fdb17.awardspace.net' , '2544173_bvmarco' , 'mox1244200' ,'2544173_bvmarco' );
        $conn = new mysqli( 'localhost' , 'root' , '' ,'bvmarco' );
        $value =mysqli_real_escape_string($conn,$value);
        $id =mysqli_real_escape_string($conn,$id);
        // Check connection
        $estadoComando=$_POST['estacoComando'];
            $IDS=$_POST['id'];
            $dataComando=$_POST['dataComando'];
            $sql = "UPDATE 'faltas' SET 'dataComando'='{$dataComando}' 'estadoComando'='{$estadoComando}' WHERE 'Id'='{$IDS}'";
            if ($conn->query($sql) === TRUE) {
                echo '<div class="alert alert-success alert-dismissable fade-in">';
                echo '  <a class="close" data-dismiss="alert" aria-label="close">&times;</a>';
                echo '  <strong>Enviado!</strong>';
                echo '</div>';
            }else{
                echo "Error updating record: " . $conn->error;
                echo '<div class="alert alert-warning alert-dismissable fade-in">';
                echo '  <a class="close" data-dismiss="alert" aria-label="close">&times;</a>';
                echo '  <strong>ERRO!</strong> Algo correu mal comunique com o developer.';
                echo '</div>';
                }
        $conn->close();
    }
}else{
    if($_SESSION['MM_Username']=="Direccao"){
        if(isset($_POST['estado'])){
            updater($_POST['estadoDirecao'],$_POST['id']);<--line 213
        }
        function updater($value,$id){
            // Create connection
            //$conn = new mysqli( 'fdb17.awardspace.net' , '2544173_bvmarco' , 'mox1244200' ,'2544173_bvmarco' );
            $conn = new mysqli( 'localhost' , 'root' , '' ,'bvmarco' );
            $value =mysqli_real_escape_string($conn,$value);
            $id =mysqli_real_escape_string($conn,$id);
            // Check connection
            if ($conn->connect_error) {
                die("Connection failed: " . $conn->connect_error);
            }
            $estadoDirecao=$_POST['estacoDirecao'];
            $IDS=$_POST['id'];
            $dataDirecao=$_POST['dataComando'];
            $sql = "UPDATE 'faltas' SET 'dataDirecao'='{$dataDirecao}' 'estadoDirecao'='{$estadoDirecao}' WHERE 'Id'='{$IDS}'";
            if ($conn->query($sql) === TRUE) {
                echo '<div class="alert alert-success alert-dismissable fade-in">';
                echo '  <a class="close" data-dismiss="alert" aria-label="close">&times;</a>';
                echo '  <strong>Enviado!</strong>';
                echo '</div>';
            }else{
                echo "Error updating record: " . $conn->error;
                echo '<div class="alert alert-warning alert-dismissable fade-in">';
                echo '  <a class="close" data-dismiss="alert" aria-label="close">&times;</a>';
                echo '  <strong>ERRO!</strong> Algo correu mal comunique com o developer.';
                echo '</div>';
            }
            $conn->close();
        }
    }
}
?>

Error:

  

Fatal error: Call to undefined function updater () in D: \ wamp64 \ www \ bvmarco \ faltas.php on line 213

<!-- language: lang-html -->
<div class="table-responsive">
    <table class="table">
    <thead>
      <tr class="jumbotron">
        <th style="text-align: center; vertical-align: middle">Numero</th>
        <th style="text-align: center; vertical-align: middle">Nome</th>
        <th style="text-align: center; vertical-align: middle">Nº Interno</th>
        <th style="text-align: center; vertical-align: middle">Categoria</th>
        <th style="text-align: center; vertical-align: middle">Tipo de falta</th>
        <th style="text-align: center; vertical-align: middle">Datas</th>
        <th style="text-align: center; vertical-align: middle">Horas</th>
        <th style="text-align: center; vertical-align: middle">Motivo</th>
        <th style="text-align: center; vertical-align: middle">Documentos</th>
        <th style="text-align: center; vertical-align: middle">Data inserção</th>
        <?php 
            if($_SESSION['MM_Username']=="Comandante"){
                echo '<th style="text-align: center; vertical-align: middle">Estado Direcção</th>';
                echo '<th style="text-align: center; vertical-align: middle">Motivo Direcção</th>';
            }if($_SESSION['MM_Username']=="Direccao"){
                echo '<th style="text-align: center; vertical-align: middle">Estado Comando</th>';
                echo '<th style="text-align: center; vertical-align: middle">Motivo</th>';
            }
        ?>
        <th style="text-align: center; vertical-align: middle">Estado</th>
      </tr>
    </thead>
    <?php do { ?>
        <form id="estado" name="estado" action="" method="post">
            <tbody>
                <thead>
                    <tr>
                        <td style="text-align: center; vertical-align: middle"><?php echo $row_faltas['Id']; ?></td>
                        <td style="text-align: center; vertical-align: middle"><?php echo $row_faltas['nome']; ?></td>
                        <td style="text-align: center; vertical-align: middle"><?php echo $row_faltas['numInterno']; ?></td>
                        <td style="text-align: center; vertical-align: middle"><?php echo $row_faltas['categoria']; ?></td>
                        <td style="text-align: center; vertical-align: middle"><?php echo $row_faltas['falta']; ?></td>
                        <?php
                            $dataDe=$row_faltas['dataDe'];
                            $dataEm=$row_faltas['dataEm'];
                            $dataAte=$row_faltas['dataAte'];
                            $horaDe=$row_faltas['horaDe'];
                            $horaAte=$row_faltas['horaAte'];
                            if($dataEm == NULL){
                                echo'<td style="text-align: center; vertical-align: middle">'.$dataDe.'/'.$dataAte.'</td>';
                                echo'<td style="text-align: center; vertical-align: middle"></td>';
                            }else{
                                if($dataDe == NULL){
                                    echo'<td style="text-align: center; vertical-align: middle">'.$dataEm.'</td>';
                                    echo'<td style="text-align: center; vertical-align: middle">'.$horaDe.'/'.$horaAte.'</td>';
                                }else{
                                    echo'<td style="text-align: center; vertical-align: middle"></td>';
                                    echo'<td style="text-align: center; vertical-align: middle"></td>';
                                }
                            }
                        ?>
                        <td style="text-align: center; vertical-align: middle"><?php echo $row_faltas['motivo']; ?></td>
                        <td style="text-align: center; vertical-align: middle"><?php echo $row_faltas['documentos']; ?></td>
                        <td style="text-align: center; vertical-align: middle"><?php echo $row_faltas['data']; ?></td>
                        <?php
                            if($row_faltas['estadoComando']=="1"){
                                echo '<td class="text-info" style="text-align: center; vertical-align: middle"><strong>Em espera</strong></td>';
                            }else{
                                if($row_faltas['estadoComando']=="2"){
                                    echo '<td class="text-success" style="text-align: center; vertical-align: middle"><strong>Autoriza</strong></td>';
                                }else{
                                    if($row_faltas['estadoComando']=="3"){
                                        echo '<td  class="text-danger"style="text-align: center; vertical-align: middle"><strong>Não Autoriza</strong></td>';
                                    }
                                }
                            }
                        ?>
                        <?php
                            $tipo=$row_faltas['tipo'];
                            if($_SESSION['MM_Username']=="Comandante"){
                                echo '<td style="text-align: center; vertical-align: middle">'.$tipo.'</td>';
                            }else{
                                if($_SESSION['MM_Username']=="Direccao"){
                                    echo'<td  class="text-danger"style="text-align: center; vertical-align: middle">
                                        <select class="form-control" name="tipo">
                                            <option></option>
                                            <option>Férias</option>
                                            <option>Falta just. c/ renumeração</option>
                                            <option>Falta just. s/ renumeração</option>
                                            <option>Falta injustificada</option>
                                        </select></td>';
                                }
                            }
                        ?>
                        <td rowspan="2" style="text-align: center; vertical-align: middle">
                            <?php
                                if($_SESSION['MM_Username']=="Comandante"){
                                    if($row_faltas['estadoComando'] == "1"){
                                        echo '<input type="hidden" id="id" name="id" value="'.$row_faltas['Id'].'" />';
                                        echo '<input type="hidden" id="dataComando" nome="dataComando" value"'.date("d-m-Y").'"/>';
                                        echo '<button name="estadoComando" id="estadoComando" type="submit" class="btn success2" value="2">Sim</button>';
                                        echo '<button name="estadoComando" id="estadocomando" type="submit" class="btn danger2" value="3">Não</button>';
                                    }else{
                                        if($row_faltas['estadoComando'] == "2"){
                                            echo '<p class="text-success"><b>Autorizado</b></p>';
                                        }else{
                                            if($row_faltas['estadoComando'] == "2"){
                                                echo '<p class="text-danger"><b>Não Autorizado</b></p>';
                                            }else{
                                                echo'';
                                            }
                                        }
                                    }
                                }else{
                                    if($row_faltas['estadoDirecao'] == "1"){
                                        echo '<input type="hidden" id="id" name="id" value="'.$row_faltas['Id'].'" />';
                                        echo '<input type="hidden" id="dataComando" nome="dataDirecao" value"'.date("d-m-Y").'"/>';
                                        echo '<button name="estadoDirecao" id="estadoDirecao" type="submit" class="btn success2" value="2">Sim</button>';
                                        echo '<button name="estadoDirecao" id="estadoDirecao" type="submit" class="btn danger2" value="3">Não</button>';
                                    }else{
                                        if($row_faltas['estadoDirecao'] == "2"){
                                            echo '<p class="text-success"><b>Autorizado</b></p>';
                                        }else{
                                            if($row_faltas['estadoDirecao'] == "3"){
                                                echo'<p class="text-success"><b>Não Autorizado</b></p>';
                                            }else{
                                                echo'';
                                            }
                                        }
                                    }
                                }

                            ?>
                        </td>
                    </tr>
                </thead>
                <?php
                if($_SESSION['MM_Username']=="Direccao"){
                    echo'<thead>
                    <tr>
                        <td class=""><strong>Despacho</strong></td>
                        <td colspan="12"><input type="text" name="despacho" class="form-control col" required></td>
                    </tr>
                </thead>';
                }
                ?>
            </tbody>
        </form>
     <?php } while ($row_faltas = mysql_fetch_assoc($faltas)); ?>
  </table>
  </div>
    
asked by anonymous 20.12.2017 / 16:39

1 answer

0

You were using a confusing structure (using two functions with the same name for different things) instead of simplifying it by creating two functions with different names (although it is possible to unify them into one). So, I changed the name of one of the functions updater to updaterComando() and the other one to updaterDirecao() , and putting them out of the if loops (of course there may be some syntactic error!). After that it looks like this:

<?php

function updaterComando($value,$id){
    // Create connection
    //$conn = new mysqli( 'fdb17.awardspace.net' , '2544173_bvmarco' , 'mox1244200' ,'2544173_bvmarco' );
    $conn = new mysqli( 'localhost' , 'root' , '' ,'bvmarco' );
    $value =mysqli_real_escape_string($conn,$value);
    $id =mysqli_real_escape_string($conn,$id);
    // Check connection
    $estadoComando=$_POST['estacoComando'];
        $IDS=$_POST['id'];
        $dataComando=$_POST['dataComando'];
        $sql = "UPDATE 'faltas' SET 'dataComando'='{$dataComando}' 'estadoComando'='{$estadoComando}' WHERE 'Id'='{$IDS}'";
        if ($conn->query($sql) === TRUE) {
            echo '<div class="alert alert-success alert-dismissable fade-in">';
            echo '  <a class="close" data-dismiss="alert" aria-label="close">&times;</a>';
            echo '  <strong>Enviado!</strong>';
            echo '</div>';
        }else{
            echo "Error updating record: " . $conn->error;
            echo '<div class="alert alert-warning alert-dismissable fade-in">';
            echo '  <a class="close" data-dismiss="alert" aria-label="close">&times;</a>';
            echo '  <strong>ERRO!</strong> Algo correu mal comunique com o developer.';
            echo '</div>';
            }
    $conn->close();
}

function updaterDirecao($value,$id){
    // Create connection
    //$conn = new mysqli( 'fdb17.awardspace.net' , '2544173_bvmarco' , 'mox1244200' ,'2544173_bvmarco' );
    $conn = new mysqli( 'localhost' , 'root' , '' ,'bvmarco' );
    $value =mysqli_real_escape_string($conn,$value);
    $id =mysqli_real_escape_string($conn,$id);
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }
    $estadoDirecao=$_POST['estacoDirecao'];
    $IDS=$_POST['id'];
    $dataDirecao=$_POST['dataComando'];
    $sql = "UPDATE 'faltas' SET 'dataDirecao'='{$dataDirecao}' 'estadoDirecao'='{$estadoDirecao}' WHERE 'Id'='{$IDS}'";
    if ($conn->query($sql) === TRUE) {
        echo '<div class="alert alert-success alert-dismissable fade-in">';
        echo '  <a class="close" data-dismiss="alert" aria-label="close">&times;</a>';
        echo '  <strong>Enviado!</strong>';
        echo '</div>';
    }else{
        echo "Error updating record: " . $conn->error;
        echo '<div class="alert alert-warning alert-dismissable fade-in">';
        echo '  <a class="close" data-dismiss="alert" aria-label="close">&times;</a>';
        echo '  <strong>ERRO!</strong> Algo correu mal comunique com o developer.';
        echo '</div>';
    }
    $conn->close();
}

if($_SESSION['MM_Username']=="Comandante"){
    if(isset($_POST['estadoComando'])){
        updaterComando($_POST['estadoComando'],$_POST['id']);
    }  
}else{
    if($_SESSION['MM_Username']=="Direccao"){
        if(isset($_POST['estado'])){
            updaterDirecao($_POST['estadoDirecao'],$_POST['id']);
        }       
    }
}
?>
    
22.12.2017 / 03:25