0

I am receiving data from the contact form on my page with Ajax. However, it does not send the data with post method.

You can see my Ajax script below.

$(document).ready(function(){
    $('#tur').on('change',function(){
        var turID = $(this).val();
        if(turID){
            $.ajax({
                type:'POST',
                url:'ajaxRez.php',
                data:'tur_id='+turID,
                success:function(html){
                    $('#turadi').html(html);

                }
            }); 
        }else{
            $('#turadi').html('<b>Önce Tur Türünü Seçin</b>');
        }
    });   
});

I am using below codes to set up a dropdown menu.

<tr>
                        <td><b>Tur Türü:</b> </td>
                        <td>
                            <select class="custom-select" name="tur" id="tur">
                                <option value="">Lütfen Seçin</option>
                                <option value="gunluk">Günlük Tur</option>
                                <option value="cokgunlu">Çok Günlük Tur</option>
                                <option value="ozeltur">Özel Tur</option>
                                <option value="ozeltur">Kiralama</option>
                            </select>
                        </td>
                        <td><b>Tur Adı:</b> </td>
                        <td>
                        <div  id="turadi" > <b>Tur seçimi yapın</b>
                        </div>
                            
                        </td>
                    </tr>

My ajaxRez.php file is as below.

<?php


//Include database configuration file
include('config.php');

if(isset($_POST["tur_id"])){
    //Dataları çek
    $tur_id= $_POST['tur_id'];
    $bugun = date('Y-m-d H:m:s');
    
        if ($tur_id=="gunluk") {
            $query = "SELECT * FROM events WHERE color LIKE '#0071c5' AND start >= '$bugun' ORDER BY start ASC";                            // mavi günlük
        }elseif ($tur_id=="cokgunlu") {
            $query = "SELECT * FROM events WHERE color LIKE '#008000' OR color LIKE '#40E0D0' AND start >= '$bugun' ORDER BY start ASC"; }  // turkuaz ve yeşil otel ve tekne
        elseif ($tur_id=="ozeltur") {
            $query = "SELECT * FROM events WHERE color LIKE '#FFD700' AND start < '$bugun' ORDER BY start ASC"; }                           // sarı özel tur
        elseif ($tur_id=="kiralama") {
            $query = "SELECT * FROM events WHERE color LIKE '#FF0000' AND start < '$bugun' ORDER BY start ASC"; }                           // kırmızı kiralama
    
    $run_query = mysqli_query($link, $query);
    
    //Sonuçları say
    $count = mysqli_num_rows($run_query);
    
    //Turların listesini çıkart
    if($count > 0){
        echo '
        <select class="custom-select" name="turadi" >
        <option value="">Lütfen Seçin</option>';
        while($row = $run_query->fetch_assoc()){
        $id=$row['id'];
        $baslik=$row['title'];
        $tarih=tarihDuzenle(tarihduzelt($row['start']));
        echo "<option value='$id'> $baslik / $tarih</option>";
        } echo "</select>";
    }else{ ?>
        Başlangıç: <input type="text" class="form-control" id="datepicker" name="baslangic" placeholder="13/06/2021"/> Bitiş: <input type="text" class="form-control" id="datepicker" name="bitis" placeholder="13/06/2021"/>
   <? }
}


?>

When I POST from my contact form I get the below warning

Notice: Undefined index: turadi in...

So the drop down menu contents do show up successfully however when I POST the form I get the "Notice: Undefined index: turadi in..." warning. Therefore, my contact form does not post the "turadi" value.

How can I overcome this issue?

Oguz Han
  • 29
  • 8

0 Answers0