javascript - When I click on li tag, it get data-value, but when I insert into it has null value


I get the li tag data-value when I on click. Now I need use the value insert back into the database but it shows null value in my database. But I use console.log it shows value.

How to get the value and insert into database?

mymoviemanagement.php :

$movie has value null

    if (isset($_POST["btn_adddate"])) {

            $s_date2 = $_POST['s_date2'];
            $movie = $_POST['movie_id'];
            $asd = "sdsd";

            if($stmt = $conn->prepare("INSERT INTO movie_date (date,movie_id) VALUES (?,?)")) {
                $stmt->bind_param("si", $s_date2, $movie );
                echo "successful adddate";
                echo $movie;
                echo $asd;
                echo "fail adddate";

Javascript inside mymoviemanagement.php:


$(".ul_movie2").on('click', 'li', function () {

    var movie_id = $(this).attr('data-value');
    if(movie_id !== "") {
            success:function(response) {


   <form action="mymoviemanagement.php" name="adddate" role="form" method="post" id="adddate" >

    <div id="selectmovie2" data-toggle="dropdown" tabindex="0" ><span >Select Movie</span>
      <ul id="m_movie" >

        $sql = "SELECT DISTINCT,, movie.image 
                FROM movie 
                INNER JOIN movie_genre 
                ON = movie_genre.movie_id 
                INNER JOIN genre ON = movie_genre.genre_id";
        $res = mysqli_query($conn, $sql);
        if(mysqli_num_rows($res) > 0) {
          while($row = mysqli_fetch_object($res)) {
            echo '<li data-value="' . $row->id . '" ><img src="' . $row->image . '" >' . $row->name . '</li>';




I guess the problem might be that yourmove_id databse column expects an INTEGER while you are sending a STRING type through the AJAX request.

Can you post here your HTML code, because without it, we don't have a complete information about your situation...




Actually I got the value.

But I should change:

<input type="text" value="" id="result">;


<input type="text" value="" id="result" name="result">;

So at PHP:

 $movie = $_POST['result'];

will get the value.

I gt mistake myself, just need addonname="result" at input tag. So only can get the value$_POST['result'].

People are also looking for solutions to the problem: Get variable data outside from the Switch Statement in PHP


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.