Advertisement
Guest User

final post comment

a guest
Mar 31st, 2015
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 6.77 KB | None | 0 0
  1. <?php
  2.    
  3.    session_start();
  4.    $s_firstName =$_SESSION['firstName'];
  5.    $s_lastName =$_SESSION['lastName'];
  6.    if(!isset($_SESSION["post_id"])) {
  7.        
  8.        $s_post_id =$_SESSION['post_id'];
  9.    }
  10.  
  11.    
  12.    if(isset($_SESSION["user_id"]))
  13.    {
  14.        $servername = "localhost";
  15.        $username = "essalaal";
  16.        $password = "computer";
  17.        $dbname = "essalaal";
  18.        
  19.        // Create connection
  20.        $mysqli = new mysqli($servername, $username, $password, $dbname);
  21.        // Check connection
  22.        if ($mysqli->connect_error) {
  23.             die("Connection failed: " . $mysqli->connect_error);
  24.         }
  25.        
  26.         $post_id=$_GET['post_id'];
  27.         $_SESSION["post_id"]=$s_post;
  28.         $sql= "select users.firstName, users.lastName, post.content, post.image, post.date
  29.         from users, post
  30.         where users.user_id = post.user_id and post.post_id=$post_id";
  31.         $result=$mysqli->query($sql);
  32.  
  33.        
  34.         if (isset($_POST["submit"])) {
  35.             $postText = $mysqli->real_escape_string($_POST['postText']);
  36.             if(($_FILES["image2"]["error"]==0)){
  37.                 upload();
  38.             } else {
  39.                 $s_user=$_SESSION['user_id'];
  40.                 $s_post=$_SESSION['post_id'];
  41.                 $sql="INSERT INTO comment (user_id, content, post_id)
  42.                 VALUES ('$s_user','$postText','$post_id')";
  43.                 $result = $mysqli->query($sql);
  44.                 echo "$sql";
  45.             }
  46.           // header('Location: status_detail.php');
  47.  
  48.         }
  49.        
  50.         $mysqli->close();
  51.        
  52.     } else {
  53.         header('Location: login_form.php');
  54.     }
  55.  
  56. $target_file="" ;
  57. function upload()
  58. {
  59.     global $postText;
  60.     global $mysqli;
  61.     global $target_file;
  62.    
  63.    
  64.     $target_dir = "uploads/";
  65.     $target_file = $target_dir . basename($_FILES["image2"]["name"]);
  66.     $uploadOk = 1;
  67.     $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
  68.    
  69.     // Check if image file is a actual image or fake image
  70.     if(isset($_POST["submit"])) {
  71.        
  72.         $check = getimagesize($_FILES["image2"]["tmp_name"]);
  73.         if($check !== false) {
  74.             //echo "File is an image - " . $check["mime"] . ".";
  75.             $uploadOk = 1;
  76.         } else {
  77.             echo "File is not an image.";
  78.             $uploadOk = 0;
  79.         }
  80.     }
  81.    
  82.     // Check file size
  83.     if ($_FILES["image2"]["size"] > 500000) {
  84.         echo "Sorry, your file is too large.";
  85.         $uploadOk = 0;
  86.     }
  87.    
  88.     // Allow certain file formats
  89.     if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" ) {
  90.        echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
  91.         $uploadOk = 0;
  92.     }
  93.    
  94.     // Check if $uploadOk is set to 0 by an error
  95.     if ($uploadOk == 0) {
  96.         echo "Sorry, your file was not uploaded.";
  97.         // if everything is ok, try to upload file
  98.     } else {
  99.         if (move_uploaded_file($_FILES["image2"]["tmp_name"], $target_file)) {
  100.             //echo "The file ". basename( $_FILES["image"]["name"]). " has been uploaded.";
  101.             //echo "$target_file";
  102.             $s_user=$_SESSION['user_id'];
  103.             $sql="INSERT INTO comment (user_id, content, image)
  104.             VALUES ('$s_user','$postText','$target_file')";
  105.             $result = $mysqli->query($sql);
  106.            
  107.             if($result){
  108.                 header('Location: news_feed.php');
  109.             } else {
  110.                 echo "Error.<br />";
  111.                 header('Location: post_status.php');
  112.             }
  113.            
  114.         } else {
  115.             echo "Sorry, there was an error uploading your file.";
  116.         }
  117.     }
  118. }
  119.  
  120.     ?>
  121.  
  122.  
  123. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  124. <html xmlns="http://www.w3.org/1999/xhtml">
  125.     <head>
  126.         <link rel="stylesheet" type="text/css" href="custom.css"/>
  127.         <title>Post Comment</title>
  128.         <script type="text/javascript" src="validate.js"> </script>
  129.        
  130.     </head>
  131.    
  132.     <body>
  133.         <header>
  134.             <h1>iAmMe</h1>
  135.         </header>
  136.         <a class="logout" href="logout_form.php">Logout</a>
  137.         <a class="post_status" href="post_status.php">Post Status</a>
  138.  
  139.         <fieldset>
  140.             <legend>SHARE A COMMENT</legend>
  141.             <?php
  142.                while($row=$result->fetch_assoc()) {
  143.                 ?>
  144.            
  145.             <div class="status">
  146.                 <div class="info">
  147.                     <img class="user" src="placeholder3.jpg" alt = "user" />
  148.                     <input type="button" value= "Like!" class="like" id="like1" onclick="colorChange(1)"/>
  149.                    
  150.                     <p class="name">
  151.                     <span> <?=$row['firstName']?> </span>
  152.                     <span> <?=$row['lastName']?> </span>
  153.                    
  154.                     </p>
  155.                     <p class="time" >
  156.                     <span> <?=$row['date']?> </span>
  157.                     </p>
  158.                     <br/>
  159.                    
  160.                 </div>
  161.                
  162.                 <div class="statusText">
  163.                     <span> <?=$row['content']?> </span>
  164.                     <br/>
  165.                     <?php
  166.                        if($row['image'] != NULL){
  167.                        ?>
  168.                     <img src= "<?=$row['image']?>" width="75" height="75"/>
  169.                     <?php
  170.                        }
  171.                        ?>
  172.                    
  173.                 </div>
  174.                
  175.             </div>
  176.             <?php
  177.                }
  178.                ?>
  179.  
  180.             <div class="comment">
  181.                
  182.                 <img class="user" src="placeholder3.jpg" alt = "user"/>
  183.                
  184.                 <p class="name">
  185.                 <?php
  186.                    echo "$s_firstName $s_lastName";
  187.                    ?>
  188.                     </p><br/>
  189.                           <form id = "post_comment" action="post_comment.php" method="post" accept-charset="utf-8" onsubmit=" return empty();" enctype="multipart/form-data" >
  190.                              
  191.                 <span class="error" id ="empty"></span><br/>
  192.                 <textarea id="postText" name ="postText"rows="6" cols="50" placeholder="Share your thoughts!"  oninput ="updateCounter()" maxlength ="1000"></textarea>
  193.                 <br/><br/>
  194.                 <span id = "count"> 1000</span>
  195.                 <br/><br/>
  196.                
  197.                 <input type="submit" value="SHARE" name = "submit"  />
  198.                
  199.                 <input type="file" name ="image2" value="UPLOAD IMAGE"/>
  200.  
  201.             </div>
  202.             </form>
  203.            
  204.         </fieldset>
  205.     </body>
  206. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement