0

Im creating some blog for practicing PHP and MySQL.

Im using this ajax to send data to PHP script:

<script type="text/javascript">
    $(document).ready(function(){
        function search(){
            var tag=$("#tagSearch").val();
            var tags=$("#tags").val();
            if(tag!=""){
                //$("#tagHolder").html();
                $.ajax({
                   type:"post",
                    url:"gettag.php",
                    data:{tag:tag},
                    success:function(data){
                        $("#tagHolder").append(data);
                        $("#tagSearch").val("");
                    }
                });
            }
            if(tags != ""){
                $.ajax({
                   type:"post",
                    url:"getposts.php",//it do get to here
                    data:{tags:tags},
                    success:function(data){
                        $("#recipeHolder").append(data);
                    }
                });
            }
        }

        $("#tagenter").click(function(){
            search();
        });

        $('#tagSearch').keyup(function(e){
            if(e.keyCode == 13){
                search();
            }
        });
    });
</script>

It does get to where i have made a comment in the ajax. Then it fails on the SQL i do in the PHP script:

$tags = mysqli_real_escape_string($con, $_POST["tags"]);

$results = mysqli_query($con, SELECT * FROM posts INNER JOIN post_tags ON posts.post_id = post_tags.post_id INNER JOIN tags ON posts.post_tags = tags.tag_id"); //Here it fails
$found = mysqli_num_rows($results);//This one results in error because it expects 1 but gets nothing

if($found > 0){
    while($row=mysqli_fetch_array($result)){
        echo '<div class="tags">'. $row['tag'] . "</div>";
    }
}
mysqli_close($con);
?>

I have made some comments in the php script so you can see where it gets before leaving an error.

I need to find all posts from the post table where the table post_tags(contains postid (both int values) and posttag) id is equal to the post table id and the post_tags posttag is equal to the table tags id.

0 Answers0