1

I know this question has been asked over and over but I have some troubles I cannot solve. I cannot retrieve an input value (text_guasto) while I can successfully retrieve the first one(title_guasto)

This is the form

<form action="segnala-guasti.query.php" method="POST">

   <input type="text" class="form-control" name ="title_guasto" maxlength='30' id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Riassumi il problema">
                              
 <textarea name="text_guasto" id="" cols="30" rows="5" class="form-control" placeholder="Descrivi il problema"></textarea>     
                             
  <input type="file" class="form-control" id="file">
  <label for="file" class="file_label"><i class="fa fa-file-image-o"></i>Carica foto del guasto</label>
                               
   <button type="submit" name = 'submit-guasto' class="btn btn-primary">Segnala</button>
   </form>

This is the POST:

if(isset($_POST["submit-guasto"])) { 
     $title_guasto = htmlspecialchars($_POST['title_guasto']);
     $text_guasto = htmlspecialchars($_POST['text_guasto']); 

ERROR: Notice: Undefined index: text_guasto in C:\xampp\htdocs\php-projects\pernis\public_html\file_user\segnala-guasti.query.php on line 7

Thank you

  • When submitting, is the textarea empty? If it is it wont be posted. Try: `isset($_POST['text_guasto']) ? htmlspecialchars($_POST['text_guasto']) : '';` – Bossman Oct 01 '20 at 14:56

1 Answers1

1

It means there is no value assigned to your POST variable use isset() to check it:

if(isset($_POST['text_guasto'])){
  $text_guasto = htmlspecialchars($_POST['text_guasto']); 
}

or:

$text_guasto = isset($_POST['text_guasto']) ? htmlspecialchars($_POST['text_guasto']) : '';
Angel Deykov
  • 1,199
  • 1
  • 9
  • 15