Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- $s_firstName =$_SESSION['firstName'];
- $s_lastName =$_SESSION['lastName'];
- if(!isset($_SESSION["post_id"])) {
- $s_post_id =$_SESSION['post_id'];
- }
- if(isset($_SESSION["user_id"]))
- {
- $servername = "localhost";
- $username = "essalaal";
- $password = "computer";
- $dbname = "essalaal";
- // Create connection
- $mysqli = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($mysqli->connect_error) {
- die("Connection failed: " . $mysqli->connect_error);
- }
- $post_id=$_GET['post_id'];
- $_SESSION["post_id"]=$s_post;
- $sql= "select users.firstName, users.lastName, post.content, post.image, post.date
- from users, post
- where users.user_id = post.user_id and post.post_id=$post_id";
- $result=$mysqli->query($sql);
- if (isset($_POST["submit"])) {
- $postText = $mysqli->real_escape_string($_POST['postText']);
- if(($_FILES["image2"]["error"]==0)){
- upload();
- } else {
- $s_user=$_SESSION['user_id'];
- $s_post=$_SESSION['post_id'];
- $sql="INSERT INTO comment (user_id, content, post_id)
- VALUES ('$s_user','$postText','$post_id')";
- $result = $mysqli->query($sql);
- echo "$sql";
- }
- // header('Location: status_detail.php');
- }
- $mysqli->close();
- } else {
- header('Location: login_form.php');
- }
- $target_file="" ;
- function upload()
- {
- global $postText;
- global $mysqli;
- global $target_file;
- $target_dir = "uploads/";
- $target_file = $target_dir . basename($_FILES["image2"]["name"]);
- $uploadOk = 1;
- $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
- // Check if image file is a actual image or fake image
- if(isset($_POST["submit"])) {
- $check = getimagesize($_FILES["image2"]["tmp_name"]);
- if($check !== false) {
- //echo "File is an image - " . $check["mime"] . ".";
- $uploadOk = 1;
- } else {
- echo "File is not an image.";
- $uploadOk = 0;
- }
- }
- // Check file size
- if ($_FILES["image2"]["size"] > 500000) {
- echo "Sorry, your file is too large.";
- $uploadOk = 0;
- }
- // Allow certain file formats
- if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" ) {
- echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
- $uploadOk = 0;
- }
- // Check if $uploadOk is set to 0 by an error
- if ($uploadOk == 0) {
- echo "Sorry, your file was not uploaded.";
- // if everything is ok, try to upload file
- } else {
- if (move_uploaded_file($_FILES["image2"]["tmp_name"], $target_file)) {
- //echo "The file ". basename( $_FILES["image"]["name"]). " has been uploaded.";
- //echo "$target_file";
- $s_user=$_SESSION['user_id'];
- $sql="INSERT INTO comment (user_id, content, image)
- VALUES ('$s_user','$postText','$target_file')";
- $result = $mysqli->query($sql);
- if($result){
- header('Location: news_feed.php');
- } else {
- echo "Error.<br />";
- header('Location: post_status.php');
- }
- } else {
- echo "Sorry, there was an error uploading your file.";
- }
- }
- }
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <link rel="stylesheet" type="text/css" href="custom.css"/>
- <title>Post Comment</title>
- <script type="text/javascript" src="validate.js"> </script>
- </head>
- <body>
- <header>
- <h1>iAmMe</h1>
- </header>
- <a class="logout" href="logout_form.php">Logout</a>
- <a class="post_status" href="post_status.php">Post Status</a>
- <fieldset>
- <legend>SHARE A COMMENT</legend>
- <?php
- while($row=$result->fetch_assoc()) {
- ?>
- <div class="status">
- <div class="info">
- <img class="user" src="placeholder3.jpg" alt = "user" />
- <input type="button" value= "Like!" class="like" id="like1" onclick="colorChange(1)"/>
- <p class="name">
- <span> <?=$row['firstName']?> </span>
- <span> <?=$row['lastName']?> </span>
- </p>
- <p class="time" >
- <span> <?=$row['date']?> </span>
- </p>
- <br/>
- </div>
- <div class="statusText">
- <span> <?=$row['content']?> </span>
- <br/>
- <?php
- if($row['image'] != NULL){
- ?>
- <img src= "<?=$row['image']?>" width="75" height="75"/>
- <?php
- }
- ?>
- </div>
- </div>
- <?php
- }
- ?>
- <div class="comment">
- <img class="user" src="placeholder3.jpg" alt = "user"/>
- <p class="name">
- <?php
- echo "$s_firstName $s_lastName";
- ?>
- </p><br/>
- <form id = "post_comment" action="post_comment.php" method="post" accept-charset="utf-8" onsubmit=" return empty();" enctype="multipart/form-data" >
- <span class="error" id ="empty"></span><br/>
- <textarea id="postText" name ="postText"rows="6" cols="50" placeholder="Share your thoughts!" oninput ="updateCounter()" maxlength ="1000"></textarea>
- <br/><br/>
- <span id = "count"> 1000</span>
- <br/><br/>
- <input type="submit" value="SHARE" name = "submit" />
- <input type="file" name ="image2" value="UPLOAD IMAGE"/>
- </div>
- </form>
- </fieldset>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement