indefinite index

Asked

Viewed 484 times

0

Good evening, I have a code where I do an Insert into,but this returning me error, and I am unable to solve, in the same field is printed in the database, page and content. The page is registered but the content causes error; and the error is: Notice: Undefined index: content my code:

       $pagina_editar = $_POST['pagina'];
       $content_editar = $_POST['content'];
       if(isset($_POST['cadastrar']) && $_POST['cadastrar'] == 'envia_form'){
$cadatrar_pagina = mysqli_query($conexao,"INSERT INTO lp_page (pagina, content) VALUES ('$pagina_editar', '$content_editar')")or die(mysqli_error($conexao));
       }

       if(isset($_POST['editar_post']) && $_POST['editar_post'] == 'envia_form'){
$atualiza_pagina = mysqli_query($conexao,"UPDATE lp_page SET content='$content_editar' WHERE pagina = '$pagina_editar'") or die (mysqli_error($conexao));
       }

      $pagina_de_edicao = $_POST['pagina'];

        $pega_pagina = mysqli_query($conexao,"SELECT id, pagina, content FROM lp_page WHERE pagina = '$pagina_de_edicao'")or die(mysqli_error($conexao));
           if(@mysqli_num_rows($pega_pagina) <= '0'){
     ?>

     <form action="" method="post" enctype="multipart/form-data" name="cadastrar_pagina">
     <input type="hidden" name="pagina" value="<?php echo $pagina_de_edicao;?>" />
     <textarea name="content" rows="30" cols=""></textarea>
     <input type="hidden" name="cadastrar" value="envia_form" />
     <input type="submit" value="Cadastrar" name="Cadastrar" class="cadastro_btn" />
     </form>    

     <?php

      }else{
        while($res_pagina = mysqli_fetch_array($pega_pagina)){
            $id = $res_pagina[0];
              $pagina = $res_pagina[1];
                $content = $res_pagina[2];  
   ?>
      <form action="" method="post" enctype="multipart/form-data" name="edita_pagina">
       <input type="hidden" name="pagina" value="<?php echo $pagina_de_edicao;?>"/>
      <textarea name="content" cols="" rows="30"> <?php echo $content; ?></textarea>
      <input type="hidden" name="editar_post" value="envia_form" />
      <input name="Editar" type="submit" value="Editar" class="cadastro_btn" />
      </form>
<?php
}
 }
 ?>

the error is happening on the line: $content_edit = $_POST['content']; can anyone help me? Thanks

  • Why does the form have multiplart/form-data ? The <form ...> and </form> must be outside the looping. Try these changes, and if possible also add the code PHP.

  • http://answall.com/questions/how-saber-se-form-%C3%A9-sent/89142#89142

  • this other one also: http://answall.com/questions/89960/como-validar-cada-tipo-date-receivedde-um-formul%C3%A1rio/90026#90026

1 answer

2


First, "Notice" is not a mistake.

php is only notifying you that the element of the $_POST array, whose index is 'content', has not been defined.

It’s easy to see why: See that you set the variable '$content_edit' before check if there is a POST request, that is, if there is an $_POST array.

Workaround: Set the variables after checking for the POST type request.

if(
 isset($_POST['cadastrar']) && 
 $_POST['cadastrar'] == 'envia_form')
{
  $pagina_editar = $_POST['pagina'];
  $content_editar = $_POST['content'];
  $cadatrar_pagina = mysqli_query($conexao,"INSERT INTO lp_page (pagina, content) VALUES ('$pagina_editar', '$content_editar')")or die(mysqli_error($conexao));
}
  • I think you forgot to treat the other two variables $_POST['pagina'] and $_POST['content']. But this is of less.. what is worth correcting the logic error of AP.

  • Thank you very much dear Marcos Kubis, thanks. I have had many difficulties in php, because I am beginner. the good thing is that we find people who are dedicated to helping. May Christ continue to bless you.Thank you..

Browser other questions tagged

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