PHP update undefine

Asked

Viewed 59 times

-1

I can’t update the database

php faults.

<?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>
  • 1

    Your question needs to have content, you need to contextualize what you’re doing, and what your problem is and what you’ve tried so far, and only then show your code and the error you’re generating.

  • So you can already understand? If you need to change or add something to understand say I do

  • What is the file faltas.php? Where is the line 213? With this code it is difficult to identify the problem, try to put only what is necessary to reproduce the error

  • the file missing.php was what I put there and the line 213 just identified as comment /<-- line 213

  • It won’t work, you’re calling the function before it exists, you need to create the function before calling it

  • What do you mean? how should I do it

  • Do the same in this link

  • A tip from here on the site, when answering someone via comment, puts @ along with the name of the person so that it receives a notification, I only saw that you answered why I reloaded the page, the only one that does not need to be mentioned in order to receive the notification is the author of the question

  • @Denisrudneidesouza now appears this error Notice: Undefined index: dateWhat comes from the code $dataComando=$_POST['dateComando'];

  • Did you directly access the file? If yes will give this error, will only exist if you send a request POST for the page in question, I advise you to try to review the code, I think the problem is how it was written

  • I already changed the code but does not update me and does not give any error @Denisrudneidesouza

Show 6 more comments

1 answer

0


You were using a confusing structure (using two functions with the same name for different things) instead of simplifying 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 for updaterComando() and the other to updaterDirecao(), and putting them outside the if loops (Of course there may be some syntactical error!). After that it became so:

<?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']);
        }       
    }
}
?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.