redirect when condition met
<p>I'm having trouble redirecting after a count hits 13.</p>

<p>I have bunch of images that a user can click on to add to their list in the db, when they click, an on click js script fires and triggers updatelist.php.  </p>

<p>That part works fine, within updatelist.php I need it to insert and then check the table to see if its reached a count of 13 yet, if so, it needs to redirect to a new page.</p>

<p>The insert works fine, but its not redirecting.  below is my updatelist.php code</p>

<pre><code>&lt;?php
include('connect.php');
session_start();
$username=$_SESSION['username'];

$image = $_GET['image'];


    $query = mysql_query("SELECT * FROM tbl_movies cross join tbl_users WHERE image_on = '$image' and username = '$username'");
    while ($row = mysql_fetch_assoc($query))
                        {
                            $movieid = $row['id'];
                            $userid = $row['UserID'];
                        }
    $query2 = mysql_query("select * from tbl_movies cross join tbl_users where image_off = '$image' and username = '$username'");   
    while ($row2 = mysql_fetch_assoc($query2))
                                {
                                    $mid = $row2['id'];
                                    $uid = $row2['UserID'];
                                }   

    $numrows = mysql_num_rows($query);
    $numrowz = mysql_num_rows($query2);

        if ($numrows!=0)
            {
                $queryInsert = mysql_query("insert into tbl_user_lists (userid_fk,movie_id_fk) values ('$userid','$movieid')"); 

                $query5=mysql_query("select l.* from tbl_user_lists as l join tbl_users on l.userid_fk=tbl_users.UserID where username='$username'");
                $updatecount = mysql_num_rows($query5);
                if ($updatecount == 13)
                    {
                        header('Location: http://localhost/main.php');
                    }
            }
        else if ($numrowz!=0)   
            {
                $queryUpdate = mysql_query("delete from tbl_user_lists where userid_fk = '$uid' and movie_id_fk = '$mid'");
            }




?&gt; 
</code></pre>

<p>Below is the script on the main page that calls the above php page</p>

<pre><code>&lt;script&gt;
$(function(){
    $('.img-swap').live('click', function() {
        var _src = $(this).attr('src');
        if (-1 == _src.indexOf('_on')) {
            $(this).attr('src',_src.replace('_off','_on')).removeClass('off');
        } else {
            $(this).attr('src',_src.replace('_on','_off')).addClass('on');
        }

        //  Update server
        $.get( 'updatelist.php?image='+escape($(this).attr('src')));
        $(this).toggleClass("on");
    });
});
&lt;/script&gt;    
</code></pre>
