-1

My jquery code is:

$.post('action/edit_breakdown.php', {id: id,program: program,st_name: st_name,p_name: p_name,fob_name: fob_name,track_no: track_no,date: date,currency: currency,image_name: image_name},
    function(data){
    $("#message").html(data);
    //$("#editBreakdown").attr('disabled','disabled');
    $("#message").hide();
    $("#message").fadeIn(1500); //Fade in the data given by the insert.php file
    /*$('#editBreakdown').each(function(){
      setTimeout(function() { window.location.reload(true); }, 2000);
    });*/
    });

to insert record i used the action page like :

<?php
    require_once("../config/dbConnect.php");
    $image_name=$_FILES['image_name']['name'];
    $tmpName=$_FILES['image_name']['tmp_name'];

    if($image_name)
    {
    /*$photo=$_FILES['photo']['name'];
    $tmpName=$_FILES['photo']['tmp_name'];*/
    $ext=substr(strchr($image_name,"."),1);
    $rand = mt_rand(100000, 999999);
    $image_name=$rand.".".$ext;
    $filePath="pictures/".$photo;
    //echo "this is ".$filePath;
    $result=move_uploaded_file($tmpName,"../".$filePath);
    thumbnail("../pictures", "../pictures","$image_name",200,$ext);
    }
    echo $BreakdownUpdate = "UPDATE breakdowns SET image='$filePath' WHERE id='$id'";
    $query = mysql_query($BreakdownUpdate) or die(mysql_error());
    if($query)
    {
        echo "<div class='oMsg1 oMsgError1'>Breakdown successfully Updated </div>";
    }
    else
    {
        echo "<div class='oMsg oMsgError'>Breakdown Update failed,Try again </div>";
    }


?>

My problem is,this code shows an error below :

Undefined index: image_name in C:\xampp\htdocs\marchand\action\edit_breakdown.php on line 1

How can i solve this problem??

1 Answers1

1

So you are trying to upload a file.

Your jQuery code is NOT sending data from a file, it's only sending a parameter "image_name" that contains a string, and which might be the files name.

Uploading a file needs a totally different approach, see How can I upload files asynchronously? for an explanation on how to code it yourself and some recommendations of libraries to use.

Community
  • 1
  • 1
bjelli
  • 9,752
  • 4
  • 35
  • 50
  • but please see above jquery code,is there any possible way to insert image with my code?? – Amit Chowdhury May 05 '13 at 08:12
  • @Amit, yes you can. From the page that bjelli links to, it seems there is a new way to do things (HTML5 only, you'll need to see if browser coverage is acceptable to you) or using a jQuery plugin. The latter is not AJAX _per se_, but it will look much the same. Follow one of the instructions on that page and see if it works for you! – halfer May 05 '13 at 09:42