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..

6
  • Possible duplicate of stackoverflow.com/questions/10809937/undefined-index-with-post Commented Mar 31, 2018 at 5:51
  • $name = $_POST['txtEName'] Commented Mar 31, 2018 at 6:22
  • echo var_dump is unnecessary. var_dump prints the output automatically Commented Mar 31, 2018 at 7:57
  • @ArmKh $_REQUEST will find either post or get variables, so that's not the issue Commented Mar 31, 2018 at 7:58
  • @Seena, you can not submit a form contains file via ajax, you can see stackoverflow.com/questions/2320069/jquery-ajax-file-upload Commented Mar 31, 2018 at 8:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.