0

I am trying to pass my data along with an image to php but it was throwing error undefined index my code is as follows

HTML

<form class="form-horizontal" name="event" id="event" enctype="multipart/form-data">
 <input type="text" name="txtEName" id="txtEName" required/>
 <input type="text" name="txtEFree" required placeholder="(in minutes)"/>
 <input type="text" name="txtEFirstPay" required/>
 <input type="text" name="txtEFirstDuration" placeholder="(in minutes)"/>
 <input type="file" name="files[]" multiple/> 
 <button type="button" id="saveEvent">SAVE</button>
</form

AJAX

 $("#saveEvent").on('click',(function() {
      var formData = new FormData($("#event"));
      $.ajax({
        url: "saveEvent.php", 
        type: 'POST',
        data: formData, 
        contentType: false,
        cache: false
        processData:false,
        success: function(data)
        {
          //further...
        }
      });
     }));

PHP

<?php
  require_once ("Php/db_connect.php");
  $name=$_REQUEST['txtEName'];
  echo var_dump($name);
  $free=$_REQUEST['txtEFree'];
  fpay=$_REQUEST['TxtEFirstPay'];
  $fduration=$_REQUEST['txtEFirstDuration'];
  $filename=$_FILES['filename']['name'];
  //upload code follows...
 ?>

When i try to echo $name its showing the error

Notice: Undefined index: txtEName

what is the problem in this. anybody please help..

Muhammad Hassaan
  • 7,296
  • 6
  • 30
  • 50
Seena
  • 29
  • 1
  • 6
  • Possible duplicate of https://stackoverflow.com/questions/10809937/undefined-index-with-post – Joseph_J Mar 31 '18 at 05:51
  • `$name = $_POST['txtEName']` – ArmKh Mar 31 '18 at 06:22
  • echo var_dump is unnecessary. var_dump prints the output automatically – ADyson Mar 31 '18 at 07:57
  • @ArmKh $_REQUEST will find either post or get variables, so that's not the issue – ADyson Mar 31 '18 at 07:58
  • @Seena, you can not submit a form contains file via ajax, you can see https://stackoverflow.com/questions/2320069/jquery-ajax-file-upload – flyingfox Mar 31 '18 at 08:26
  • @lucumt the very link you've posted, in the accepted answer, has an edit which mentions that this is now possible, in most new browsers. That question is 8 years old, things have changed. Support starts from following desktop browsers versions. IE 10+, Firefox 4.0+, Chrome 7+, Safari 5+, Opera 12+ – ADyson Mar 31 '18 at 08:30

0 Answers0