Logan McInnis
2019-12-02 18:52:03 -08:00
9 changed files with 74 additions and 62 deletions

View File

@@ -3,14 +3,14 @@ server {
listen [::]:80;
root /var/www/;
index landingPage.html
index index.html
server_name _;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location / {
try_files $uri $uri/ /landingPage.html =404;
try_files $uri $uri/ /index.html =404;
}
location ~ \.php$ {

View File

@@ -49,6 +49,13 @@
echo "</pre>";
?>
<h3>$_POST</h3>
<?php
echo "<pre>";
print_r($_POST);
echo "</pre>";
?>
<h3>$_SESSION</h3>
<?php
echo "<pre>";

View File

@@ -13,13 +13,17 @@
</style>
<h2><font color="white">Friendbook</h2>
<button type="button" onclick="window.location.href = 'friends.html'">See Friends</button>
<button type="button" onclick="window.location.href = 'messages.html'">See Messages</button>
<button type="button" onclick="window.location.href = 'contacts.html'">See Contacts</button>
<button type="button" onclick="window.location.href = 'search.php'">Search</button>
<button type="button" onclick="window.location.href = 'sendMessage.php'">Message Someone</button>
<button type="button" onclick="window.location.href = 'findFriend.html'">Find a New Friend</button>
<button type="button" onclick="window.location.href = 'pendingFriend.html'">Check Pending Friends</button>
<button type="button" onclick="window.location.href = '/friends.html'">See Friends</button>
<br><br>
<button type="button" onclick="window.location.href = '/messages.html'">See Messages</button>
<br><br>
<button type="button" onclick="window.location.href = '/search.php'">Search</button>
<br><br>
<button type="button" onclick="window.location.href = '/sendMessage.php'">Message Someone</button>
<br><br>
<button type="button" onclick="window.location.href = '/findFriend.html'">Find a New Friend</button>
<br><br>
<button type="button" onclick="window.location.href = '/pendingFriend.html'">Check Pending Friends</button>
</body>

View File

@@ -1,21 +0,0 @@
<!DOCTYPE html>
<html>
<body>
<style>
body {
background-color: #3B5998;
}
</style>
<h2><font color="white">Friendbook</h2>
<button type="button" onclick="window.location.href = 'friends.html'">See Friends</button>
<button type="button" onclick="window.location.href = 'messages.html'">See Messages</button>
<button type="button" onclick="window.location.href = 'contacts.html'">See Contacts</button>
<button type="button" onclick="window.location.href = 'search.php'">Search</button>
<button type="button" onclick="window.location.href = 'sendMessage.php'">Message Someone</button>
<button type="button" onclick="window.location.href = 'findFriend.html'">Find a New Friend</button>
<button type="button" onclick="window.location.href = 'pendingFriend.php'">Check Pending Friends</button>
</body>
</html>

View File

@@ -1,5 +1,10 @@
<?php
session_start();
if (isset($_POST['Submit'])){
$_SESSION['loginData'] = $_POST;
header("Location: /loginCheck.php");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
@@ -17,7 +22,7 @@
</style>
<div class="message"><?php if($_SESSION["loginError"]!="") { echo $_SESSION["loginError"]; } ?></div>
<h2><font color="white">Please Login</h2>
<form action="loginCheck.php" method="post">
<form action="" method="post">
User&colon;
<input type="text" name="username" placeholder="Username"><br>
Password&colon;

View File

@@ -7,7 +7,31 @@ body {
}
</style>
<?php
$servername = "localhost";
$username = "web";
$password = "Password456";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$username = $_POST["name"];
$message = $_POST["message"];
$query0 = "Select max(messageID) from messages";
mysqli_query($conn, $query0) or die('Error querying database.');
$maxID = mysqli_query($conn, $query0);
$maxID = $maxID + 1;
$query1 = "Insert into messages (messageID, sender, recipient, message, date, haveread) values({$maxID}, , {$username}, {$message}, NOW(), 'N')";
mysqli_query($conn, $query1) or die('Error inserting into database.');
mysqli_close($conn);
?>
</body>
</html>

View File

@@ -20,10 +20,18 @@ if ($conn->connect_error) {
}
echo "Connected successfully";
$query = "Select * from contacts where fname = " + $fname + " and lnam = " + $lname;
$query = "Select * from contacts where fname = {$fname} and lnam = {$lname}";
mysqli_query($conn, $query) or die('Error querying database.');
print $query;
$result = mysqli_query($conn, $query);
$row = mysqli_fetch_array($result);
while ($row = mysqli_fetch_array($result)) {
echo $row['fname'] . ' ' . $row['lnam'] . ': ' . $row['username'] .'<br />';
}
mysqli_close($conn);
?>
</body>

View File

@@ -9,33 +9,7 @@ body {
<h2><font color="white">Send a message</h2>
<?php
$name = $message = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
$name = "";
} else {
$comment = test_input($_POST["name"]);
}
if (empty($_POST["Message"])) {
$message = "";
} else {
$message = test_input($_POST["message"]);
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<form method="post" action="messageSender.php">
Who are you sending it to?: <br><input type="text" name="name" value="<?php echo $name;?>">
<br><br>
Message: <br><textarea name="message" rows="5" cols="40"><?php echo $message;?></textarea>

View File

@@ -7,6 +7,7 @@ body {
</style>
<?php
$username = $_POST["username"];
$servername = "localhost";
@@ -20,11 +21,21 @@ $conn = new mysqli($servername, $username, $password);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
$query = "Select * from contacts where username = " + $username;
echo "<br>";
$query = "Select * from contacts where username = {$username}";
mysqli_query($conn, $query) or die('Error querying database.');
$result = mysqli_query($conn, $query0);
$row = mysqli_fetch_array($result);
while ($row = mysqli_fetch_array($result)) {
echo $row['username'] . ': ' . $row['fname'] . ' ' . $row['lnam'] .'<br />';
}
print $query;
mysqli_close($conn);
?>
</body>