Table editing in PHP

Asked

Viewed 33 times

-1

Hello, I have a problem in my code that I did not find the problem.

I am trying to edit a table information, but it keeps generating the error below, if anyone can help I will be immensely grateful.

Error showing
Warning: Trying to access array offset on value of type null in C: xampp htdocs eletrictel panel projects_edit.php online 244

// Classe Projeto Editar.php
<?php
include('../class/classe_verifica_login.php');
include_once('../class/classe_conexao.php');
$id = filter_input(INPUT_GET, "id", FILTER_SANITIZE_NUMBER_INT);
$result_empresa = "SELECT * FROM empresa WHERE id='$id' LIMIT 1";
$resultado_empresa = mysqli_query($conexao, $result_empresa);
$row_empresa = mysqli_fetch_assoc($resultado_empresa);
?>

<form method="POST" action="projeto_editar.php">
                  <div class="row">
                    <div class="col-md-5">
                      <div class="form-group">
                        <label class="bmd-label-floating">ID ( Desabilitado )</label>
              //linha 244          <input type="text" name="id" id="id" class="form-control" value="<?php echo $row_empresa['id']; ?>" disabled>
                      </div>
                    </div>
                    <div class="col-md-3">
                      <div class="form-group">
                        <label class="bmd-label-floating">Empresa</label>
                        <input name="nm_empresa" type="text" value="<?php echo $row_empresa['nm_empresa']; ?>" class="form-control">
                      </div>
                    </div>
                    <div class="col-md-4">
                      <div class="form-group">
                        <label class="bmd-label-floating">Status</label>
                        <input name="pj_status" type="text" value="<?php echo $row_empresa['pj_status']; ?>" class="form-control">
                      </div>
                    </div>
                  </div>
                  <div class="row">
                    <div class="col-md-6">
                      <div class="form-group">
                        <label class="bmd-label-floating">Nome do projeto</label>
                        <input name="nm_projeto" type="text" value="<?php echo $row_empresa['nm_projeto']; ?>" class="form-control">
                      </div>
                    </div>
                    <div class="col-md-6">
                      <div class="form-group">
                        <label class="bmd-label-floating">Número de EI</label>
                        <input name="nm_ei" type="text" value="<?php echo $row_empresa['nm_ei']; ?>" class="form-control">
                      </div>
                    </div>
                  </div>
                  <div class="row">
                    <div class="col-md-12">
                      <div class="form-group">
                        <label class="bmd-label-floating">Nome da concessionária</label>
                        <input name="nm_concessionaria" type="text" value="<?php echo $row_empresa['nm_concessionaria']; ?>" class="form-control">
                      </div>
                    </div>
                  </div>
                  <div class="row">
                    <div class="col-md-4">
                      <div class="form-group">
                        <label class="bmd-label-floating">Cidade</label>
                        <input name="nm_cidade" type="text" value="<?php echo $row_empresa['nm_cidade']; ?>" class="form-control">
                      </div>
                    </div>
                    <div class="col-md-4">
                      <div class="form-group">
                        <label class="bmd-label-floating">Kilometragem</label>
                        <input name="qnt_kilometragem" type="text" value="<?php echo $row_empresa['qnt_kilometragem']; ?>" class="form-control">
                      </div>
                    </div>
                    <div class="col-md-4">
                      <div class="form-group">
                        <label class="bmd-label-floating">Quantidade de postes</label>
                        <input name="qnt_postes" type="text" value="<?php echo $row_empresa['qnt_postes']; ?>" class="form-control">
                      </div>
                    </div>
                    <!--
                      <div class="col-md-4">
                        <div class="form-group">
                          <label for="cadastro" class="bmd-label-floating">Cadastro</label>
                          <input name="cadastro" type="text" class="form-control">
                        </div>
                      </div>
                      -->
                  </div>
<button type="submit" class="btn btn-primary pull-right">Atualizar</button>

```

```
// Classe Projeto Editar.php

<?php
include('../class/classe_verifica_login.php');
include_once('../class/classe_conexao.php');

$id = filter_input(INPUT_POST, "id", FILTER_SANITIZE_NUMBER_INT);
$nm_empresa = filter_input(INPUT_POST, 'nm_empresa', FILTER_SANITIZE_STRING);
$pj_status = filter_input(INPUT_POST, 'pj_status', FILTER_SANITIZE_STRING);
$nm_projeto = filter_input(INPUT_POST, 'nm_projeto', FILTER_SANITIZE_STRING);
$nm_ei = filter_input(INPUT_POST, 'nm_ei', FILTER_SANITIZE_STRING);
$nm_concessionaria = filter_input(INPUT_POST, 'nm_concessionaria', FILTER_SANITIZE_STRING);
$nm_cidade = filter_input(INPUT_POST, 'nm_cidade', FILTER_SANITIZE_STRING);
$qnt_kilometragem = filter_input(INPUT_POST, 'qnt_kilometragem', FILTER_SANITIZE_STRING);
$qnt_postes = filter_input(INPUT_POST, 'qnt_postes', FILTER_SANITIZE_STRING);

$result_up_empresa = "UPDATE empresa SET nm_empresa='$nm_empresa', pj_status='$pj_status', modificado=NOW() WHERE id='$id'";
$resultado_up_empresa = mysqli_query($conexao, $result_up_empresa);

if(mysqli_affected_rows($conexao)) {
    header("Location: projetos_listar.php");
} else {
    $_SESSION['negado'] = true;
    header("Location: projetos_editar.php?id=$id");
}
?>
```

1 answer

0


You are trying to access a non-existent index in the array. Do a var_dump in $row_enterprise, and see what it returns to you.

Browser other questions tagged

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