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){
$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();
}
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