I need to add a php text

1

I need to add a text that I define in a textarea that is at the end of the code but when wanting to enter it for the first time I get an indefinite variable as I do to correct this attached code

<?php

session_start();
if (!isset($_SESSION['user_login_status']) AND $_SESSION['user_login_status'] != 1 or
$_SESSION['user_permision'] != "Administrador") 
{
    header("location: login.php"); 
    exit;                                              
    }


require_once ("config/db.php");
require_once ("config/conexion.php");

$active_ticket="active";    
$title="Prestamos   | Simple Stock";
        $Nticket= $_GET['Nticket'];
     $incidencia= $_GET['incidencia'];
        $tema= $_GET['tema'];
        $detalle= $_GET['detalle'];
         $firstname= $_GET['firstname'];
        $text = $_POST['editor'];
      ?>
     <html>
      <head>
<?php include("head.php");
    include("navbarhelp.php");?>
<script src="ckeditor/ckeditor.js"></script>
</head>
<body>
    <div class="subject">Asunto:<strong><?php echo $tema; ?></strong></div>
    <div id="ticketThread">
    <table class="thread-entry message" cellspacing="0" 
      cellpadding="1"width="800" boder="0">
        <tbody>
            <tr>
            <th>
            <div>
                <span class="textra"></span>
                <span><?php echo $firstname; ?></span>
                </div>    
            </th>
            </tr>
        <tr>
            <td class="thread-body"><div><?php echo $detalle ?></div></td>
            </tr>
        </tbody>
        </table>
        <table class="thread-entry response" cellspacing="0" cellpadding="1" 
      width="800" border="0">
        <tbody>
            <tr>
            <th>
                <div>
                Respuesta <span class="textra"></span>
                <span></span>
                </div>
                </th>
            </tr>
            <tr><br>
                <td class="thread-body"><br><div><?php echo $text ?><br>
    </div></td></tr>
            </tbody></table></div>

    <form action="respuestas.php?Nticket=<?php echo $Nticket?>&incidencia=<?
   =$incidencia?>&tema=<?=$tema?>&detalle=<?=$detalle?>&firstname=<?
   =$firstname?>" 
  method="POST">
<textarea class="ckeditor" name="editor"></textarea>

        <input type="submit"  value="Respuesta">
   </form>
        </body>

             <?php 

if(isset($_POST['editor'])){

    $text = $_POST['editor'];
   $query = mysqli_query($con, "UPDATE ticket SET Respuesta='".$text."'  
       WHERE Nticket='".$Nticket."'");



}

   ?>

this is before entering a value

and after entering a value in the textarea

    
asked by Kevin Salazar 28.11.2017 в 17:20
source

3 answers

1

Well the code $text = $_POST['editor']; that you have on line 22 can be removed because you really do not need it there since you are asking for that same variable below in your code to proceed to save it:

if(isset($_POST['editor'])){
   $text = $_POST['editor'];
   $query = mysqli_query($con, "UPDATE ticket SET Respuesta='".$text."'  
       WHERE Nticket='".$Nticket."'");
}

Now imagine that what you wanted to achieve was to obtain the answer that had previously been saved in the system for which you should make a query:

$sql = "SELECT Respuesta FROM ticket WHERE Nticket = $Nticket";
$result = mysqli_query($con, $sql);
$row = mysqli_fetch_array($result);

With this you capture the value you have entered and then update it if necessary.

    
answered by 28.11.2017 / 20:46
source
2

Your problem is on line 22; you are looking for a variable POST in the same way as variables GET . Try changing:

$text = $_POST['editor'];

For something like this:

!isset($_POST['editor']) ? : $text = $_POST['editor'];

Normally one checks within the variable $_SERVER to know what type of request was made, POST or GET and decisions are made in the flow of your scripts from there but that example that I share also It works.

Looking a little deeper, it seems that you can also simply delete line 22 since you are doing the same thing at the end of the script:

<?php 

if(isset($_POST['editor'])){

  $text = $_POST['editor'];
  ...
    
answered by 28.11.2017 в 17:31
1

The problem is when you load everything, the PHP, capture once the values that you indicate in lines 15 to 22, the previous ones to $text , do not give an error because they are by the method $ _GET, but $text is for $ _POST and at the time of uploading you have not spent anything for $ _POST.

solution options:

  • Sort the code.
  • Use AJAX.
  • Change $text to method $_GET .
  • answered by 28.11.2017 в 17:28