0

Hello Everyone.
Please how can i make a Like button in PHP.. i want the button to be clicked. the button
see the far i 've gone with the attachements...

like feature starts from... line 84 - 107

Attachments
<?php
//include db connection file
require_once 'admin/dbconnect.php';

?>



<!DOCTYPE html>
<html lang="en">

    <head>
        <meta charset="UTF-8">
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="description" content="">
        <meta name="author" content="">

        
        <link rel="stylesheet" href="css/font-awesome.min.css">
        
        <link rel="stylesheet" href="css/bootstrap.min.css">
        <link  rel="stylesheet" href="css/greencss.css">
        <link rel="stylesheet" href="css/comment.css"/>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
        <script type="text/javascript" src="jquery.min.js"></script>
        
        

        <title>Green Blog | <?php echo $ViewTitle; ?></title>
    </head>
    <body class="news">

        <?php include 'includes/header.php'; ?>

        <!-- submit news modal -->
        <div class="container">
            <h2></h2>

        </div>
        
        <?php
        $sel = "SELECT * FROM blogposts WHERE post_id=".$_GET['post_id'];
        $resView = mysql_query($sel);
        if(mysql_num_rows($resView) > 0){
            
        
        while ($row1 = mysql_fetch_array($resView)) {
            $ViewId = $row1['post_id'];
            $ViewTitle = $row1['post_title'];
            $ViewCont = $row1['post_content'];
            $ViewAuthor = $row1['post_author'];
            $ViewDate = $row1['post_date'];

        ?>
        <div class="container-fluid" style="margin-top: 50px;">
            
            <div class="row" style="margin-top: 100px;">
                
                <div class="col-md-8"><!-- Start of One full post col -->
                    <div class="FullPostDiv">
                        
                        
                        <h2 class="text-success text-uppercase"><?php echo $ViewTitle; ?></h2>
                        <br/>
                        
                        <p class="pFullPost">
                        
                            <?php echo $ViewCont; ?>
                        
                        </p>
                        
                        <br/>
                        
                        <div>
                            
                     
                            
                        </div>
                        
                    </div>
                    
                            <?php
                            if('POST' == $_SERVER['REQUEST_METHOD']) {
                                
                            $sql = "UPDATE gr_likes set `likes` = `likes`+1 where `post_id` =".$_GET['post_id'];
                            $result=mysql_query($sql);
                            
                            if($sql){//if 
                                $sql1 = "SELECT * FROM gr_likes WHERE post_id".$_GET['post_id'];
                                $result1 = mysql_query($sql1);
                                if(mysql_num_rows($result1) > 0){
                                    
                                    while ($row2 = mysql_fetch_row($result1)) {
                                        $likeNo = $row2['likes'];
                                    }
                                }
                            }
                            }
                                ?>
                    
                    <form action="<?php echo $_SERVER['PHP_SELF']?>" method="POST" style="margin-left: 30px;">
                        <input type="hidden" name="post_id" value="<?php echo $_GET['post_id']?>"/> 
                        <button type = "submit" class="btn btn-lg btn-success" name='like'><i class="fa fa-thumbs-o-up"></i>Like</button>
                        <span class=""><?php echo $likeNo; ?></span><!--number of likes -->
                    </form>
                    
                    <br/>
                    <div style="margin-left: 50px;">
                        <h3 class="text-success text-uppercase">Drop Your Comment</h3>
                        
                        
                        <form method="POST" name="form" action="comment.php">
                            
                            <div class="form-group">
                                <input type="hidden" name="post_id" value="<?php echo $_GET['post_id']?>">
                            </div>
                            <div class="form-group">
                                <input class="form-control" type="text" id="name" name="name" placeholder="Your name..." />
                            </div>
                            <div class="form-group">
                                <textarea name="comment" id="message" class="form-control" placeholder="Your comment..."></textarea>
                            </div>
                            <div class="form-group">
                                <button type="submit" class="btn btn-lg btn-success" name="submit">Comment</button>
                            </div>
                            
                        </form>
                        
                        <?php
                        
                        ?>
                        
                        <div class="space">
                            
                            
                            
                        </div>
                        
                    
                    </div>
                </div><!-- End of Full post col -->
                
                <div class="col-md-4"><!--Start of Sidebar col-->
                    
                    <?php
                    
                    include 'sidebar.php';
                    ?>
                    
                </div><!-- End of Sidebar COL-->
                
            </div>
            
        </div>
        
        
        
        
        
        <?php
// include footer
include 'includes/footer.php';
?>
        



            <script src="js/jquery-2.2.3.js"></script>
            <script type="text/javascript" src="js/bootstrap.min.js"></script>

    </body>
</html>
<?php
                                    }
                                }
                            ?>
4
Contributors
3
Replies
31
Views
5 Months
Discussion Span
Last Post by rubberman
-3

hello destiny_3 with this code stop programming at all , do something else in your free time , apparently you don't have it . If you still want to be a programmer return to basics and LEARN them

Votes + Comments
Not cool man
We should be helping people, not insulting them
0

PHP is a fully object oriented language - C++ for web servers. Stop intermingling your PHP and HTML or other client-side code. IE, write the HTML or JavaScript code for the button and put that in a PHP class method and/or variable. Then, just output it to the client. You will need to use some HTTP to process the return data. Most of the time I look at "commercial" PHP code and then go throw up in the bathroom!

FWIW, I spent a couple of years at Nokia writing production PHP code, including a cell phone emulator. I also had to debug and fix the output HTTP code for the 5.4.1 version of PHP that was the latest/greatest at the time. Serious bugs there. Oh, and I had to do all of that inside of 2 months!

Edited by rubberman

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.