UNIVERSITY OF REGINA Department of Computer Science CS 215 – Web & Database Programming Winter 2021 Assignment #5: Micro-Blogging Website – Server-Side Programming Due: Tuesday March 30, 2021 by 11:55...

1 answer below »
UNIVERSITY OF REGINA Department of Computer Science CS 215 – Web & Database Programming Winter 2021 Assignment #5: Micro-Blogging Website – Server-Side Programming Due: Tuesday March 30, 2021 by 11:55 PM This is the fourth in the series of assignments for building a micro-blogging website. In the first assignment, you built an interface mock-up of the site. In the second assignment, you implemented the client-side programming. In the third assignment, you designed and built the database. For this assignment, you will use PHP to implement the server-side programming. The last assignment will focus on performing AJAX-based updates of the website. Because the assignments build upon each other, you may wish to made modifications to your previous assignment submission before starting this assignment. Now that you have designed and constructed the database, the next step is to use PHP to access the database, save user-specified content, and dynamically construct specific elements of the web pages. You are not permitted to use third-party libraries that simplify or abstract the PHP coding. This assignment is divided into two different components: A. PHP Database Entry & File Upload There are a number of pages that result in the database being updated with new information. These pages are listed below, with an explanation of what is to be done for each. 1. Sign-up Form • validate the form data to ensure that the required fields are present and that they do not contain illegal data; if there is a problem, return to the sign-up form with a generic error message • if the data is good, add it to the database and return the user to the Main Page so they can login • for the user avatar image/graphic upload, move the uploaded file to an appropriate location within the web application file structure, and save its location (URL) in the database • see http://www.php.net/manual/en/features.file-upload.postmethod.php for more information on managing file uploads 2. Post/Repost Form • only allow access to this page if the user has successfully logged in • validate the form data to ensure that all of the required elements are present and in the proper format CS 215 (Winter 2021): Assignment #5 2 • if the data is good, add it to the database and return the user to the Post List Page • if this is a repost, ensure that the ID of the original post is saved with this post 3. Like and Dislike • the ability to update the like and dislike information should only be possible when the user is logged in • when a logged-in user clicks on the like or dislike icon for a post or repost, the system should save this information in the database and the reload the page • if a user likes or dislikes a post, they should be able to undo their selection • a user can only like or dislike a given post, and not both B. PHP Database Query There are a number of pages that result in the database being queried. These pages are listed below, with an explanation of what is to be done for each. 1. Login Form • query the database with the login credentials to verify that the user exists and provided the correct password • if the information is correct, save the necessary information to know who this user is within a session variable, and redirect to the Post List Page 2. Post List Page • query the database for the 20 most recent posts/re-posts • List the posts with the most recent first • each post should include the screenname of the poster, the avatar image/graphic for the user account, the date/time of the post, the content of the post/repost, and the counts of the likes and dislikes for the post • if a particular post is a repost, the original post author, content, and date/time should also be shown 3. User Detail Page • this page is accessed by clicking on the screenname of a post author within the Post List Page, as well as the name of an original post author for a repost • query the database to retrieve only the posts for this individual user • order and display these posts in the same manner as for the Post List Page above (showing all, instead of limiting it to 20) Since the pages you have build for the previous assignments will each be modified, you should ensure that they are still HTML5 compliant (following the syntax rules of CS 215 (Winter 2021): Assignment #5 3 XTHML), use CSS, and that there is a proper separation of the specification of the content from the specification of the presentation rules, the specification of the JavaScript code, and the specification of the PHP processing code. Grading Scheme This assignment will be graded out of 10 marks, based on the following criteria: 1 mark: Sign-up form processing 1 mark: Creation of new posts 1 mark: Creation of new reposts 1 mark: Like and dislike 1 mark: Logic for like and dislike 1 mark: Login and saving the state in a session variable 2 marks: Dynamically generating the Poll List Page content 1 mark: Proper handling of the reposts in the Poll List Page and User Detail Page 1 mark: Dynamically generating the User Detail Page content Submissions All of the files for this assignment should be posted to your personal website on Hercules (a separate directory for this assignment, with a link on your home page), as well as uploaded to UR Courses (a single zip file). A simple submission log file should be provided that includes your name, student number, class number, the URL of where you have posted the files on Hercules, and a listing of the files you have submitted along with a short explanation of the purpose of each file. Failure to provide these support documents will result in delays in the grading of your assignment and possibly a deduction in your grade. Late submissions (up to 12 hours) will not be accepted with an automatic 20% grade deduction (-2 marks). If there are exceptional circumstances that kept you from submitting your assignment on-time, you should consult with your instructor as soon as you are able to do so. See the syllabus for more details on the late policy for this class.
Answered 1 days AfterMar 31, 2021

Answer To: UNIVERSITY OF REGINA Department of Computer Science CS 215 – Web & Database Programming Winter 2021...

Sandeep Kumar answered on Apr 01 2021
147 Votes
assignment2/dislike.php
session_start();
if(isset($_SESSION["email"]))
{
    //If somebody is logged in, display a welcome message
    $email=$_SESSION["email"];
    $conn = mysqli_connect("localhost","li992","961209","li992");
    if ($conn->connect_error)
    {
        die ("Connection failed: " . $conn->connect_error);
    }
    $q="SELECT * FROM USER where email = '$email'";
    $r = $conn->query($q);
    $row = $r->fetch_assoc();
    $username=$row["username"];
    $DOB=$row["DOB"];
    $userID=$row["user_id"];
    
// get like and dislike value and store it when it triggered
    if(isset($_POST["blogID"])){
        $inputBID=$_POST["blogID"];
        $inputRID=0;
        $testLike="SELECT * FROM Likes WHERE Repost_id='$inputRID' AND Post_id='$inputBID'AND User_id='$userID'";
        $testr=mysqli_query($conn,$testLike);
        if(mysqli_num_rows($testr)==0){
            $inp
utLike="INSERT INTO Likes (Repost_id,Post_id,User_id,value) VALUES ('$inputRID','$inputBID','$userID',2)";
            $conn->query($inputLike);
            $result=1;
        }
        else{
            $result=0;
        }
        echo $result;
        $conn->close();
    }
    
    if(isset($_POST["repostID"])){
        $inputBID=0;
        $inputRID=$_POST["repostID"];
        $testLike="SELECT * FROM Likes WHERE Repost_id='$inputRID' AND Post_id='$inputBID'AND User_id='$userID'";
        $testr=mysqli_query($conn,$testLike);
        if(mysqli_num_rows($testr)==0){
            $inputLike="INSERT INTO Likes (Repost_id,Post_id,User_id,value) VALUES ('$inputRID','$inputBID','$userID',2)";
            $conn->query($inputLike);
            $result=1;
        }
        else{
            $result=0;
        }
        echo $result;
        $conn->close();
    }
    
}
?>
assignment2/dislike.png
assignment2/index.html


Lorem ipsum dolor sit amet consectetur adipisicing elit. Impedit est similique earum a quam quis doloremque quos dicta, ab saepe ipsam sint consequuntur velit commodi accusantium? Magni expedita libero recusandae.




Make a Post!





PrithviPatel
Oct 9, 1999 @ 5:30am

Some text..
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Minus quia veniam nam pariatur, quo amet provident, omnis, unde eligendi natus voluptas ab quidem. Suscipit eveniet veniam numquam repudiandae, quidem dolorum nobis odio ducimus vero earum iste ut aspernatur dolores provident nihil illo dolor est, quibusdam quis tempore. Veritatis, consectetur eaque!



10
10


PrithviPatel
Oct 9, 1999 @ 5:30am

Some text..
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Minus quia veniam nam pariatur, quo amet provident, omnis, unde eligendi natus voluptas ab quidem. Suscipit eveniet veniam numquam repudiandae, quidem dolorum nobis odio ducimus vero earum iste ut aspernatur dolores provident nihil illo dolor est, quibusdam quis tempore. Veritatis, consectetur eaque!



10
10


PrithviPatel
Oct 9, 1999 @ 5:30am
This is a repost..
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Temporibus, odit?



10
10



PrithviPatel
Oct 9, 1999 @ 5:30am

Some text..
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Minus quia veniam nam pariatur, quo amet provident, omnis, unde eligendi natus voluptas ab quidem. Suscipit eveniet veniam numquam repudiandae, quidem dolorum nobis odio ducimus vero earum iste ut aspernatur dolores provident nihil illo dolor est, quibusdam quis tempore. Veritatis, consectetur eaque!



10
10

Lorem ipsum dolor sit, amet consectetur adipisicing elit. Assumenda quasi modi, obcaecati quibusdam aspernatur non! Ratione id corrupti amet animi perspiciatis, quibusdam recusandae fugit ipsam alias tenetur? Voluptatem, nobis rem.
assignment2/like.php
session_start();
if(isset($_SESSION["email"]))
{
    //If somebody is logged in, display a welcome message
    $email=$_SESSION["email"];
    $conn = mysqli_connect("localhost","li992","961209","li992");
    if ($conn->connect_error)
    {
        die ("Connection failed: " . $conn->connect_error);
    }
    $q="SELECT * FROM USER where email = '$email'";
    $r = $conn->query($q);
    $row = $r->fetch_assoc();
    $username=$row["username"];
    $DOB=$row["DOB"];
    $userID=$row["user_id"];
    
    
// get like and dislike value and store it when it triggered
    if(isset($_POST["blogID"])){
        $inputBID=$_POST["blogID"];
        $inputRID=0;
        $testLike="SELECT * FROM Likes WHERE Repost_id='$inputRID' AND Post_id='$inputBID'AND User_id='$userID'";
        $testr=mysqli_query($conn,$testLike);
        if(mysqli_num_rows($testr)==0){
            $inputLike="INSERT INTO Likes (Repost_id,Post_id,User_id,value) VALUES ('$inputRID','$inputBID','$userID',1)";
            $conn->query($inputLike);
            $result=1;
        }
        else{
            $result=0;
        }
        echo $result;
        $conn->close();
    }
    
    if(isset($_POST["repostID"])){
        $inputBID=0;
        $inputRID=$_POST["repostID"];
        $testLike="SELECT * FROM Likes WHERE Repost_id='$inputRID' AND Post_id='$inputBID'AND User_id='$userID'";
        $testr=mysqli_query($conn,$testLike);
        if(mysqli_num_rows($testr)==0){
            $inputLike="INSERT INTO Likes (Repost_id,Post_id,User_id,value) VALUES ('$inputRID','$inputBID','$userID',1)";
            $conn->query($inputLike);
            $result=1;
        }
        else{
            $result=0;
        }
        echo $result;
        $conn->close();
    }
    
}
?>
assignment2/login.html
Login to UOFR_SPEAKS

Username:

Password:



assignment2/Login.php
$validateL = true;
$reg_EmailL = "/^\w+@[a-zA-Z0-9_]+?\.[a-zA-Z0-9]{2,3}$/";
$reg_PswdL = "/^(\S*)?\d+(\S*)?$/";
$emailL = "";
$error = "";
if (isset($_POST["submittedL"]) && $_POST["submittedL"])
{
$emailL = trim($_POST["email"]);
$passwordL = trim($_POST["Pass"]);

$db = new mysqli("localhost", "li992", "961209", "li992");
if ($db->connect_error)
{
die ("Connection failed: " . $db->connect_error);
}
$q="SELECT * FROM USER where email = '$emailL' AND password = '$passwordL'";
$r = $db->query($q);
$row = $r->fetch_assoc();
if($emailL != $row["email"] && $passwordL != $row["password"])
{
$validateL = false;
echo"part1";
}
else
{
$emailLMatch = preg_match($reg_EmailL, $emailL);
if($emailL == null || $emailL == "" || $emailLMatch == false)
{
$validateL = false;
echo"part2";
}

$pswdLen = strlen($passwordL);
$passwordLMatch = preg_match($reg_PswdL, $passwordL);
if($passwordL == null || $passwordL == "" || $pswdLen < 8 || $passwordLMatch == false)
{
$validateL = false;
echo"part3";
}
}

if($validateL == true)
{
session_start();
$_SESSION["email"] = $row["email"];
$_SESSION["uname"] = $row["username"];
header("Location: index.php");
$db->close();
exit();
}
else
{
$error = "The email/password combination was incorrect. Login failed.";
$db->close();
}
}
?>




Login Page





    

        Please enter your Username and Password to login
        
        
            
                
Email:...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here