vendredi 3 novembre 2017

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 database but it show null value on my database. But I use console.log it show 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 );
                $stmt->execute();
                $stmt->close();
                echo "successful adddate";
                echo $movie;
                echo $asd;
            }
            else{
                echo "fail adddate";
            }
        }

Javascript inside mymoviemanagement.php:

 <script>

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

    var movie_id = $(this).attr('data-value');
    console.log(movie_id)
    if(movie_id !== "") {
        $.ajax({
            url:"mymoviemanagement.php",
            data:{movie_id:movie_id},
            type:'POST',
            success:function(response) {
            }
        });
    }
});
</script>

html:

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



        <div class="nice-select dropdown-toggle" id="selectmovie2"  data-toggle="dropdown" tabindex="0" style="margin-left: 200px;  margin-top: 29px;"><span class="current">Select Movie</span>
            <ul class="dropdown-menu scrollable-menu ul_movie2" id="m_movie" >
                <?php



                $sql = "SELECT DISTINCT movie.id,movie.name, movie.image 
                                FROM movie 
                                INNER JOIN movie_genre 
                                ON movie.id = movie_genre.movie_id 
                                INNER JOIN genre ON genre.id = 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 . '"class="option"  style="margin-top:10px; margin-bottom:10px;"><img src="' . $row->image . '" style="width:50px; height:80px; margin-right:10px;">' . $row->name . '</li>';
                    }
                }

                ?>
            </ul>
        </div>
</form>




Aucun commentaire:

Enregistrer un commentaire