注意:未定义的索引:/Applications/MAMP/htdocs/FarmUpload.php中的分区

时间:2017-01-12 11:48:38

标签: php ajax xmlhttprequest

使用xmlhttprequest上传照片,但我不理解为什么它会给我以上的通知。

使用

传递值
"formData.append('district',district);
 xhr.open("POST", "/FarmUpload.php");" to FarmUpload.php

除分区值外,所有值均正确插入。

使用下面的populateSelect()函数选择分区值。

Andaman=new Array("Nicobar","North and Middle Andaman","South Andaman");

Andhra=new Array( "Anantapur","Chittoor","East Godavari","Guntur","Kadapa","Krishna","Kurnool","Nellore","Prakasam","Srikakulam","Visakhapatnam","Vizianagaram","West Godavari");

 Arunachal = new Array ("Anjaw","Changlang","Dibang Valley","East Kameng","East Siang","Kurung Kumey","Lohit","Longding","Lower Dibang Valley","Lower Subansiri","Papum Pare","Tawang",
                     "Tirap","Upper Siang","Upper Subansiri","West Kameng","West Siang");
 Assam=new Array("Baksa","Barpeta","Bongaigaon","Cachar","Chirang","Darrang","Dhemaji","Dhubri","Dibrugarh","Goalpara","Golaghat","Hailakandi","Jorhat","Kamrup","Kamrup Metropolitan","Karbi Anglong","Karimganj","Kokrajhar","Lakhimpur","Morigaon","Nagaon","Nalbari","North Cachar Hills","Sivasagar","Sonitpur","Tinsukia","Udalguri");

Bihar= new Array("Araria","Arwal","Aurangabad","Banka","Begusarai","Bhagalpur","Bhojpur","Buxar","Darbhanga",
 "East Champaran","Gaya","Gopalganj","Jamui","Jehanabad","Kaimur (Bhabua)","Katihar","Khagaria","Kishanganj","Lakhisarai","Madhepura","Madhubani",
  "Munger","Muzaffarpur","Nalanda","Nawada","Patna","Purnea","Rohtas","Saharsa","Samastipur","Saran","Sheikhpura","Sheohar","Sitamarhi","Siwan","Supaul","Vaishali","West Champaran");

 Chandigarh= new Array("Chandigarh");


 Chhattisgarh = new Array( "Balod","Baloda Bazar","Balrampur","Bastar","Bemetara","Bijapur","Bilaspur","Dhamtari","Durg","Gariaband","Janjgir-Champa","Jashpur","Kabirdham-Kawardha",                           "Kondagaon","Korba","Korea","Mahasamund","Mungeli","Narayanpur","Norh Bastar-Kanker","Raigarh","Raipur","Rajnandgaon","South Bastar-Dantewada","Sukma","Surajpur","Surguja");

  Dadra = new Array("Dadra and Nagar Haveli");

  Daman= new Array("Daman","Diu");

  Delhi= new Array("Central Delhi","East Delhi","New Delhi","North Delhi","North East Delhi","North West Delhi","South Delhi","South West Delhi","West Delhi");

   Goa=new Array("North Goa","South Goa");

    Gujarat = new Array("Ahmedabad","Amreli","Anand","Aravalli","Banaskantha","Bharuch","Bhavnagar","Botad","Chhota Udepur","Dahod","Dang","Devbhoomi Dwarka","Gandhinagar","Gir Somnath",                        "Jamnagar","Junagadh","Kheda","Kutch","Mahisagar","Mehsana","Morbi","Narmada","Navsari","Panchmahals","Patan","Porbandar","Rajkot","Sabarkantha","Surat","Surendranagar","Tapi","Vadodara","Valsad");

   Haryana = new Array("Ambala","Bhiwani","Faridabad","Fatehabad","Gurgaon","Hisar","Jhajjar","Jind","Kaithal","Karnal","Kurukshetra","Mahendragarh","Mewat","Palwal","Panchkula",
                  "Panipat","Rewari","Rohtak","Sirsa","Sonipat","Yamunanagar");

  Himachal = new Array ("Bilaspur","Chamba","Hamirpur","Kangra","Kinnaur","Kullu","Lahaul & Spiti","Mandi","Shimla","Sirmaur","Solan","Una");

  Jammu = new Array("  Anantnag","Bandipora","Baramulla","Budgam","Doda","Ganderbal","Jammu","Kargil","Kathua","Kishtwar","Kulgam","Kupwara","Leh","Poonch","Pulwama","Rajouri","Ramban","Reasi","Samba","Shopian","Srinagar","Udhampur");

  Jharkhand = new Array("Bokaro","Chatra","Deoghar","Dhanbad","Dumka","East Singhbhum","Garhwa","Giridih","Godda","Gumla","Hazaribag","Jamtara","Khunti","Koderma","Latehar","Lohardaga",                           "Pakur","Palamu","Ramgarh","Ranchi","Sahibganj","Seraikela-Kharsawan","Simdega","West Singhbhum");

  Karnataka= new Array("Bagalkot","Bellary","Belgaum","Bengaluru Rural","Bengaluru Urban","Bidar","Chamrajanagar","Chikballapur","Chikkamagaluru","Chitradurga","Dakshina Kannada",                                   "Davangere","Dharwad","Gadag","Hassan","Haveri","Gulbarga","Kodagu","Kolar","Koppal","Mandya","Mysore","Raichur","Ramanagara","Shivamogga","Tumakuru","Udupi","Uttara Kannada","Vijayapura","Yadgir");
  Kerala= new Array(" Alappuzha","Ernakulam","Idukki","Kannur","Kasargod","Kollam","Kottayam","Kozhikode","Malappuram","Palakkad","Pathanamthitta","Thiruvananthapuram","Thrissur","Wayanad");

   Lakshadweep =new Array("Lakshadweep");

   Madhya= new Array("Alirajpur","Anuppur","Ashoknagar","Balaghat","Barwani","Betul","Bhind","Bhopal","Burhanpur","Chhatarpur","Chhindwara","Damoh","Datia","Dewas","Dhar","Dindori","Guna","Gwalior","Harda","Hoshangabad","Indore","Jabalpur","Jhabua","Katni","Khandwa","Khargone","Mandla","Mandsaur","Morena","Narsinghpur","Neemuch","Panna","Raisen","Rajgarh","Ratlam","Rewa","Sagar","Satna","Sehore","Seoni","Shahdol","Shajapur","Sheopur","Shivpuri","Sidhi","Singrauli","Tikamgarh","Ujjain","Umaria","Vidisha");

    Maharashtra= new Array("Ahmednagar","Akola","Amravati","Aurangabad","Beed","Bhandara","Buldhana","Chandrapur","Dhule","Gadchiroli","Gondia","Hingoli","Jalgaon","Jalna","Kolhapur","Latur","Mumbai City","Mumbai  Suburban","Nagpur","Nanded","Nandurbar","Nashik","Osmanabad","Parbhani","Pune","Raigad","Ratnagiri","Sangli","Satara","Sindhudurg",                        "Solapur","Thane","Wardha","Washim","Yavatmal");

  Manipur = new Array("Bishnupur","Chandel","Churachandpur","Imphal East","Imphal West","Senapati","Tamenglong","Thoubal","Ukhrul");

   Meghalaya = new Array("East Garo Hills","East Khasi Hills","Jaintia Hills","Ri Bhoi","South Garo Hills","West Garo Hills","West Khasi Hills");

   Mizoram = new Array("Aizawl","Champhai","Kolasib","Lawngtlai","Lunglei","Mamit","Saiha","Serchhip");

    Nagaland = new Array("Dimapur","Kiphrie","Kohima","Longleng","Mokokchung","Mon","Peren","Phek","Tuensang","Wokha","Zunheboto");

    Orissa= new Array("Angul","Balangir","Balasore","Bargarh","Bhadrak","Boudh","Cuttack","Deogarh","Dhenkanal","Gajapati","Ganjam","Jagatsinghapur","Jajpur","Jharsuguda", "Kalahandi",                           "Kandhamal","Kendrapara","Kendujhar","Khordha","Koraput","Malkangiri","Mayurbhanj","Nabarangpur","Nayagarh","Nuapada","Puri","Rayagada","Sambalpur","Subarnapur","Sundargarh");

   Pondicherry= new Array("Karaikall","Mahe","Pondicherry","Yanam");

    Punjab= new Array("Amritsar","Barnala","Bathinda","Faridkot","Fatehgarh Sahib","Fazilka","Ferozepur","Gurdaspur","Hoshiarpur","Jalandhar","Kapurthala","Ludhiana","Mansa","Moga",                                         "Muktsar", "Nawanshahr","Pathankot","Patiala","Rupnagar","Sangrur","SAS Nagar","Tarn Taran"); 

   Rajasthan = new Array ("Ajmer","Alwar","Banswara","Baran","Barmer","Bharatpur","Bhilwara","Bikaner","Bundi","Chittorgarh","Churu","Dausa","Dholpur","Dungarpur","Hanumangarh","Jaipur","Jaisalmer","Jalore Jhalawar","Jhunjhunu","Jodhpur","Karauli","Kota","Nagaur","Pali","Pratapgarh","Rajsamand", "Sawai Madhopur","Sikar","Sirohi","Sri Ganganagar","Tonk","Udaipur");

  Sikkim= new Array("East Sikkim","North Sikkim","South Sikkim" ,"West Sikkim"); 

  Tamilnadu= new Array("Ariyalur","Chennai","Coimbatore","Cuddalore","Dharmapuri","Dindigul","Erode","Kanchipuram","Kanyakumari","Karur","Krishnagiri","Madurai","Nagapattinam",
                 "Namakkal","Perambalur", "Pudukkottai","Ramanathapuram","Salem","Sivaganga","Thanjavur","The Nilgiris","Theni","Thoothukudi","Tiruchirappalli","Tirunelveli",                               "Tiruppur","Tiruvallur","Tiruvannamalai","Tiruvarur","Vellore","Viluppuram","Virudhunagar");

  Telengana= new Array("Adilabad","Hyderabad","Karimnagar","Khammam","Mahabubnagar","Medak","Nalgonda","Nizamabad","Ranga Reddy","Warangal");

  Tripura= new Array("Dhalai","Gomati","Khowai","North Tripura","Sepahijala","South Tripura","Unakoti","West Tripura");

   Uttar= new Array("Agra","Aligarh","Allahabad","Ambedkar Nagar","Auraiya","Azamgarh","Bagpat","Bahraich","Ballia","Balrampur","Banda","Barabanki","Bareilly","Basti","Bijnor","Budaun",                    "Bulandshahar","Chandauli","Chitrakoot","Deoria","Etah","Etawah","Faizabad","Farrukhabad","Fatehpur","Firozabad","Gautam Buddha Nagar","Ghaziabad","Ghazipur","Gonda", "Gorakhpur","Hamirpur","Hardoi","Hathras","Jalaun","Jaunpur","Jhansi","Jyotiba Phule Nagar","Kannauj","Kanpur Dehat","Kanpur Nagar","Kanshiramnagar","Kaushambi",                                        "Kheri","Kushinagar","Lalitpur","Lucknow","Maharajganj","Mahoba","Mainpuri","Mathura","Mau","Meerut","Mirzapur","Moradabad","Muzaffarnagar","Pilibhit","Pratapgarh","RaeBareli","Rampur","Saharanpur","Sant Kabir Nagar","Sant  Ravidas Nagar","Shahjahanpur","Shravasti","Siddharthnagar","Sitapur","Sonbhadra","Sultanpur","Unnao","Varanasi");

  Uttaranchal = new Array("Almora","Bageshwar","Chamoli","Champawat","Dehradun","Haridwar","Nainital","Pauri Garhwal","Pithoragarh","Rudraprayag","Tehri Garhwal","Udham Singh Nagar","Uttarkashi");

  West = new Array("Bankura","Bardhaman","Birbhum","Cooch Behar","Darjeeling","East Medinipur","Hooghly","Howrah","Jalpaiguri","Kolkata","Malda","Murshidabad","Nadia","North 24 Parganas","North Dinajpur","Purulia","South 24 Parganas","South Dinajpur","West Medinipur");


 populateSelect();


 $(function() {

  $('#Statelist').change(function(){
   $('#District').html('');
    populateSelect();
   });

  });



  function populateSelect(){
cat=$('#Statelist').val();
   $('#District').append('');

   eval(cat).forEach(function(t) { 

        $('#District').append('<option>'+t+'</option>');
    });

}

FarmUpload.php

<?php @session_start();
include("inc/FarmConnect.php");

 $user=$_SESSION['id'];

 $adtitle=mysql_real_escape_string(strip_tags($_POST['adtitle']));
 $category=mysql_real_escape_string(strip_tags($_POST['category']));
 $quantity=mysql_real_escape_string(strip_tags($_POST['quantity']));
 $price=mysql_real_escape_string(strip_tags($_POST['price']));
 $address=mysql_real_escape_string(strip_tags($_POST['address']));
 $postcode=mysql_real_escape_string(strip_tags($_POST['postcode']));
 $state=mysql_real_escape_string(strip_tags($_POST['state']));
 $district=mysql_real_escape_string(strip_tags($_POST['district']));
 $contact=mysql_real_escape_string(strip_tags($_POST['contact']));
 $description=mysql_real_escape_string(strip_tags($_POST['description']));
 // $cancel=@$_POST['cancel'];

 $postad=@$_POST['postad'];

 $number="0";

 if(isset($_FILES['myFile']))
 {  

 foreach($_FILES['myFile']['tmp_name'] as $key => $tmp_name )

 {

   $filename=mysql_real_escape_string(@$_FILES['myFile']['name'][$key]);

   $path="FarmerWebImages/".$user."/";


    if (!is_dir($path)) {

    mkdir($path,0777,true);

    }

    $newpath=$path.$filename;

    move_uploaded_file($_FILES['myFile']['tmp_name'][$key],$newpath);



  mysql_query("INSERT INTO Adalbum                VALUES('','$user','','$newpath','$number',CURDATE(),CURTIME())");


 }

 }


if($postad)
{  

  if($state=='Andaman')
         {

    $state="Andaman and Nicobar Islands";
         }          
   else if($state=='Andhra')
     {
    $state="Andhra Pradesh";

     }
       else if($state=='Arunachal')
     {
    $state="Arunachal Pradesh";

     } else if($state=='Dadra')
     {
    $state="Dadra and Nagar Haveli";

     } else if($state=='Daman')
     {
    $state="Daman and Diu";

     } else if($state=='Himachal')
     {
    $state="Himachal Pradesh";

     } else if($state=='Jammu')
     {
    $state="Jammu and Kashmir";

     }
      else if($state=='Tamil')
     {
    $state="Tamil Nadu";

     }else if($state=='Uttar')
     {
    $state="Uttar Pradesh";

     }else if($state=='Madhya')
     {
    $state="Madhya Pradesh";

     }else if($state=='West')
     {
    $state="West Bengal";

     }



    if($adtitle!="" && $category!='' && $quantity!='' && $price!='' &&  $address!='' && $postcode!='' && $district!='' && $state!='' && $contact!='' && $description!='')

  {
  mysql_query("INSERT INTO Ad  VALUES('','$user','$adtitle','$category','$quantity','$price','$address','$postcode','$district','$state','$contact','$description',
                                  CURDATE(),CURTIME())");



$selectquery=mysql_query("SELECT * FROM Ad WHERE title='$adtitle' AND userid='$user' ORDER BY id DESC LIMIT 1 ");

$rows=mysql_fetch_array($selectquery);
$adid=$rows['id'];


    mysql_query("UPDATE Adalbum SET Adid='$adid', hash='1' WHERE  hash='$number' AND userid='$user'");


     header("location:http://localhost/Categories/$category");
     die();
    }

    }


    ?>

1 个答案:

答案 0 :(得分:-1)

有一个小错误,我没有把name =“district”放在select中。

现在工作正常。感谢