Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts

    .show is not showing the div

    I have a form that people can fill out to rate movies. When you click on the rate button the script send off a insert to a mysql table then it hides the form letting the user know that it was completed. It used to send a pop up window and I am trying to move that to a div that will show them that it was completed. So far the form hides and the table updates but the div is not showing and I am not sure why, tho I think it might be because the success is not being sent back correctly. The goal is to have them show what there rating was with a image showing 1-5 of them depending on what was rated. I already have some code that will do that but needs to be inserted into this script.

    Here is what I have
    form
    Code:
    <script type="text/javascript">
    $(function() {
          $('#add-rating').submit(function(event) {
                event.preventDefault()
                $(this).hide('fast');
                var movie_rating_s = $('#add-rating [name="MOVIE_RATING"]:checked').val();
                var movie_id_s = $('#add-rating [name="MOVIE_ID"]').val();
                var movie_title_s = $('#add-rating [name="MOVIE_TITLE"]').val();
                var user_id_s = $('#add-rating [name="USER_ID"]').val();
                $.ajax({type: 'POST', url: 'movie_watched.php', cache: false, timeout: 10000,
                      data: {rating: movie_rating_s, movie: movie_id_s, title: movie_title_s, user: user_id_s},
                      success: function() {
                            $('#div_show').text('You have rated the movie').show('fast');
                      },
                      error: function() {
                            $('#div_show').text('There is a problem').show('fast');
                      }
                });
          });
    });
    </script>
    <form id="add-rating">
      <input type="radio" name="MOVIE_RATING" value="1" > 1
      <input type="radio" name="MOVIE_RATING" value="2" > 2
      <input type="radio" name="MOVIE_RATING" value="3" checked="yes"> 3
      <input type="radio" name="MOVIE_RATING" value="4" > 4 
      <input type="radio" name="MOVIE_RATING" value="5" > 5 <br>
      <input type="hidden" name="MOVIE_ID" value="<?php echo $id; ?>">
      <input type="hidden" name="MOVIE_TITLE" value="<?php echo stripslashes($title); ?>">
      <input type="hidden" name="USER_ID" value="<?php echo $loggedinusername; ?>">
    <input type="submit" value="Rate">
    <div id="div_show">
    </div>
    heres the movie_watched page
    Code:
    <?php
    
    include"scripts/connect.php" ;
    	mysql_connect('localhost',$username,$password);
    @mysql_select_db($database) or die( "Unable to select database");
    
    $movie = mysql_real_escape_string($_POST['movie']);
    $user = mysql_real_escape_string($_POST['user']);
    $title= mysql_real_escape_string($_POST['title']);
    $rating= mysql_real_escape_string($_POST['rating']);
    $error = '';
    
    $userquery = mysql_query("SELECT * FROM rateing WHERE (movie_id='$move') AND (user_id='$user')");
    
    if (mysql_num_rows($userquery) > 0) {
    
    			printf("You have already played.");
    			echo "<br />";
    		}
    		else {
    
    $sql = "INSERT INTO rateing (movie_id, user_id, title, rating) VALUES ('".$movie."', '".$user."', '".$title."', '".$rating."')"; 
    $query = mysql_query($sql);
    
    if (!mysql_query($query, $conn))
    {
        $error = mysql_error();
        $return['error'] = $error;
        echo json_encode($return);
        mysql_close($conn);
    }
    else
    {
        $success = "You have rated the movie";
        $return['mysql'] = $success;
       echo json_encode($return);
        mysql_close($conn);
    }
    }
    
    
    @mysql_select_db($database) or die( "Unable to select database");
    $title = mysql_real_escape_string(urldecode($_POST["title"]));
    $rating= mysql_real_escape_string($_POST['rating']);
    $find_query="SELECT * FROM movie WHERE title='$title'";
    $find_result=mysql_query($find_query);
    
    $find_rating= mysql_result($find_result, $i, "rating");
    $find_num_votes= mysql_result($find_result, $i, "num_votes");
    
    $sum_rating = $find_rating + $rating;
    $sum_num_votes = $find_num_votes + 1;
    
    
    include"scripts/connect.php" ;
    	mysql_connect('localhost',$username,$password);
    @mysql_select_db($database) or die( "Unable to select database");
    $title= mysql_real_escape_string($_POST['title']);
    $error = '';
    
    $sql_rating = "UPDATE movie SET rating='$sum_rating', num_votes='$sum_num_votes' WHERE title='$title'"; 
    mysql_query($sql_rating) or die (mysql_error());
    
    
    ?>
    and here is the php that will show the image for the ranking that can be edited to show there ranking after voting. I don't know if this can just be added into the .show or what has to be done. This does work else where to show the average user rating.

    Code:
    			<tr>
    <td><span class="rulemain">Your Rating:</span><br>
    <?PHP if($MOVIE_RATING==1){
    ?>
    <img src="beer_mug_finish.jpg"  alt="" name="beer_mug" width="50" height="50">
    <?PHP
    }
    ?>
    <?PHP
    if($MOVIE_RATING==2){
    ?>
    <img src="beer_mug_finish.jpg"  alt="" name="beer_mug" width="50" height="50">
    <img src="beer_mug_finish.jpg"  alt="" name="beer_mug" width="50" height="50">
    <?PHP
    }
    ?>
    <?PHP
    if($MOVIE_RATING==3){
    ?>
    <img src="beer_mug_finish.jpg"  alt="" name="beer_mug" width="50" height="50">
    <img src="beer_mug_finish.jpg"  alt="" name="beer_mug" width="50" height="50">
    <img src="beer_mug_finish.jpg"  alt="" name="beer_mug" width="50" height="50">
    <?PHP
    }
    ?>
    <?PHP
    if($MOVIE_RATING==4){
    ?>
    <img src="beer_mug_finish.jpg"  alt="" name="beer_mug" width="50" height="50">
    <img src="beer_mug_finish.jpg"  alt="" name="beer_mug" width="50" height="50">
    <img src="beer_mug_finish.jpg"  alt="" name="beer_mug" width="50" height="50">
    <img src="beer_mug_finish.jpg"  alt="" name="beer_mug" width="50" height="50">
    <?PHP
    }
    ?>
    <?PHP
    if($MOVIE_RATING==5){?>
    <img src="beer_mug_finish.jpg"  alt="" name="beer_mug" width="50" height="50">
    <img src="beer_mug_finish.jpg"  alt="" name="beer_mug" width="50" height="50">
    <img src="beer_mug_finish.jpg"  alt="" name="beer_mug" width="50" height="50">
    <img src="beer_mug_finish.jpg"  alt="" name="beer_mug" width="50" height="50">
    <img src="beer_mug_finish.jpg"  alt="" name="beer_mug" width="50" height="50">
    <?PHP
    }
    ?>
    Thank you for any and all help/pointers

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Use Firebug or Chrome Developer Tools to put a breakpoint in the success and error callbacks and check where it goes.

    And where is the closing form tag </form>? If the div_show div is inside the form, then even if you show the div_show div, it will not appear as it is inside the hidden form.

  • Users who have thanked glenngv for this post:

    freemancomputer (04-29-2012)

  • #3
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,105
    Thanks
    23
    Thanked 594 Times in 593 Posts
    glenngv is correct by adding the closing form tag the script worked for me.

    Code:
    <input type="submit" value="Rate">
    </form>
    <div id="div_show">
    </div>
    </body></html>

  • Users who have thanked sunfighter for this post:

    freemancomputer (04-29-2012)

  • #4
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts
    wow, I have spent hours staring at this and my brain just threw in the ending to the form. Thanks


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •