0

Всем привет, есть проблема, мне нужно передать из поля input текст, а php файл как-будто не видит её, попробовал var_dump($_POST), но там пустой массив. Делаю через ajax. HTML:

'''
<form action="index.php" method='get' id="form">
    &lt;input type=&quot;text&quot; class=&quot;h&quot; name=&quot;comment&quot; id=&quot;comment&quot;&gt;
    &lt;input type=&quot;button&quot; id=&quot;y&quot; class=&quot;bron&quot;&gt;
&lt;/form&gt;

'''

PHP:

'''
    session_start();
    include 'index.html';
    $connect = new PDO("mysql:host=localhost; dbname=resto; charset=UTF8", 'root', 'root');
    error_reporting(E_ALL);
    ini_set("display_errors", 1);
    $connect->query("UPDATE `resto`.`stol` SET `stol1`= 1 WHERE 1");
    if(isset($_POST['comment'])){
        $r = $_POST['comment'];
        echo $r;
        var_dump($_POST);
    }
'''

JS:

'''
        $(document).ready(function() {
            // $('.h').hide();
            $('.kv').mouseover(function(){
                $(this).css('border','0.3vw solid red');
                $(this).html('Столик занят');
            })
            $('.kv').mouseout(function(){
                $(this).css('border','0.3vw solid #d4cc70');
                $(this).html('');
                $(this).css('top','-3vw');
            })
            $('.bron').on('click', function(){
                var comment = $('comment').val();
                $.ajax({
                    method: "POST",
                    url: "index.php",
                    data: { 
                        comment: comment,
                    }
                })
            })
    });

'''

Al Dv
  • 27

1 Answers1

0

Исправьте селектор, с var comment = $('comment').val(); на var comment = $('#comment').val();, а то у вас получается, что вы ищете тег с <comment>

PS: И в php еще вы обращаетесь к $_POST['comment'], хотя у вас нужно обращаться к $_POST['data']['comment'] (Тут я не прав)

PSS: в html уберите метод, как вам сказали в комментариях

rusgeli
  • 1,806