Minor fixes and closing DB connections as needed

This commit is contained in:
WilliamMiceli
2019-12-04 21:48:04 -05:00
parent 5bb11b100b
commit d5f3df965f
9 changed files with 95 additions and 95 deletions

View File

@@ -1,27 +1,29 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<body> <body>
<?php <?php
$servername = "localhost"; $servername = "localhost";
$username = "web"; $username = "web";
$password = "Password456"; $password = "Password456";
$dbname = "computer"; $dbname = "computer";
// Create connection // Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname); $conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection // Check connection
if (!$conn) if (!$conn)
{ {
die("Connection failed: " . mysqli_connect_error()); die("Connection failed: " . mysqli_connect_error());
} }
$sql = "INSERT INTO FriendList VALUES user1, argv[0], true"; $sql = "INSERT INTO FriendList VALUES user1, argv[0], true";
$result = mysqli_query($conn, $sql); $result = mysqli_query($conn, $sql);
$sql = "UPDATE FriendList SET confirm = true WHERE username = argv[0] and friend = user1"; $sql = "UPDATE FriendList SET confirm = true WHERE username = argv[0] and friend = user1";
$result = mysqli_query($conn, $sql); $result = mysqli_query($conn, $sql);
?> ?>
</body> </body>
</html> </html>
<?php
$db_connection = null;
?>

View File

@@ -54,11 +54,13 @@
$db_connection->query($sql_statement); $db_connection->query($sql_statement);
$sql_statement = "INSERT INTO friendList VALUES ('".$_SESSION["loggedInUser"]."', '".$_POST['friend']."', true)"; $sql_statement = "INSERT INTO friendList VALUES ('".$_SESSION["loggedInUser"]."', '".$_POST['friend']."', true)";
$db_connection->query($sql_statement); $db_connection->query($sql_statement);
echo "Friend request confirmed! You are both friends with each other now.";
} }
else else
{ {
$sql_statement = "INSERT INTO friendList VALUES ('".$_SESSION["loggedInUser"]."', '".$_POST['friend']."', false)"; $sql_statement = "INSERT INTO friendList VALUES ('".$_SESSION["loggedInUser"]."', '".$_POST['friend']."', false)";
$db_connection->query($sql_statement); $db_connection->query($sql_statement);
echo "Friend request sent to $_POST[\'friend\']";
} }
} }
} }

View File

@@ -1,3 +0,0 @@
<?php
phpinfo();
?>

View File

@@ -13,25 +13,19 @@
<body> <body>
<!--#include virtual="header.html" --> <!--#include virtual="header.html" -->
<!--#include virtual="topNavBar.html" --> <!--#include virtual="topNavBar.html" -->
<style> <?php
body { echo "<br>";
background-color: #3B5998; try{
} $query = "INSERT INTO messages (sender, recipient, message, date, haveread) VALUES ('".$_SESSION["loggedInUser"]."', '".$_POST["name"]."', '".$_POST["message"]."', NOW(), 'N')";
</style> $db_connection->query($query);
print("Message Has been sent");
<?php }
echo "<br>"; catch(Exception $e){
try{ echo "Exception: ".$e->getMessage().PHP_EOL;
$query = "INSERT INTO messages (sender, recipient, message, date, haveread) VALUES ('".$_SESSION["loggedInUser"]."', '".$_POST["name"]."', '".$_POST["message"]."', NOW(), 'N')"; }
$db_connection->query($query); ?>
</body>
print("Message Has been sent");
}
catch(Exception $e){
echo "Exception: ".$e->getMessage().PHP_EOL;
}
?>
</body>
</html> </html>
<?php
$db_connection = null;
?>

View File

@@ -4,21 +4,23 @@
?> ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html> <html>
<head> <head>
<link rel="stylesheet" type="text/css" href="styling.css"> <link rel="stylesheet" type="text/css" href="styling.css">
</head> </head>
<body> <body>
<!--#include virtual="header.html" --> <!--#include virtual="header.html" -->
<!--#include virtual="topNavBar.html" --> <!--#include virtual="topNavBar.html" -->
<?php <?php
echo '<pre>'; echo '<pre>';
$query = "Select * from contacts where fname = '".$_POST["fname"]."' and lname = '".$_POST["lname"]."'"; $query = "Select * from contacts where fname = '".$_POST["fname"]."' and lname = '".$_POST["lname"]."'";
foreach($db_connection->query($query) as $row){ foreach($db_connection->query($query) as $row){
print "First Name:\t".$row['fname']."\nLast Name:\t".$row['lname']."\nUsername:\t".$row['username']."\n"; print "First Name:\t".$row['fname']."\nLast Name:\t".$row['lname']."\nUsername:\t".$row['username']."\n";
} }
echo '</pre>'; echo '</pre>';
?> ?>
</body>
</body>
</html> </html>
<?php
$db_connection = null;
?>

View File

@@ -31,4 +31,6 @@
</body> </body>
</html> </html>
<?php
$db_connection = null;
?>

View File

@@ -4,24 +4,23 @@
?> ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html> <html>
<head> <head>
<link rel="stylesheet" type="text/css" href="styling.css"> <link rel="stylesheet" type="text/css" href="styling.css">
</head> </head>
<body> <body>
<!--#include virtual="header.html" --> <!--#include virtual="header.html" -->
<!--#include virtual="topNavBar.html" --> <!--#include virtual="topNavBar.html" -->
<h2><font color="white">Send a message</h2> <h2><font color="white">Send a message</h2>
<form method="post" action="messageSender.php"> <form method="post" action="messageSender.php">
Who are you sending it to?: <br><input type="text" name="name"> Who are you sending it to?: <br><input type="text" name="name">
<br><br> <br><br>
Message: <br><textarea name="message" rows="5" cols="40"></textarea> Message: <br><textarea name="message" rows="5" cols="40"></textarea>
<br><br> <br><br>
<input type="submit" class="button"> <input type="submit" class="button">
</form> </form>
</body>
</body>
</html> </html>
<?php
$db_connection = null;
?>

View File

@@ -4,7 +4,7 @@
<a href="/messagesSent.php">Sent Messages</a> <a href="/messagesSent.php">Sent Messages</a>
<a href="/search.php">Search</a> <a href="/search.php">Search</a>
<a href="/sendMessage.php">Message Someone</a> <a href="/sendMessage.php">Message Someone</a>
<a href="/findFriend.php">Find a New Friend</a> <a href="/findFriend.php">Add a Friend</a>
<a href="/pendingFriend.php">Check Pending Friends</a> <a href="/pendingFriend.php">Check Pending Friends</a>
<!--Maybe show the user's name here?--> <!--Maybe show the user's name here?-->
<a href="/logout.php" style="float:right">Logout</a> <a href="/logout.php" style="float:right">Logout</a>

View File

@@ -9,20 +9,22 @@
<link rel="stylesheet" type="text/css" href="styling.css"> <link rel="stylesheet" type="text/css" href="styling.css">
</head> </head>
<body> <body>
<!--#include virtual="header.html" --> <!--#include virtual="header.html" -->
<!--#include virtual="topNavBar.html" --> <!--#include virtual="topNavBar.html" -->
<?php <?php
echo '<br><pre>'; echo '<br><pre>';
echo "Username\tFirst Name\tLast Name\n\n"; echo "Username\tFirst Name\tLast Name\n\n";
$query = "SELECT * FROM contacts WHERE username REGEXP '.*".$_POST["username"].".*'"; $query = "SELECT * FROM contacts WHERE username REGEXP '.*".$_POST["username"].".*'";
foreach($db_connection->query($query) as $row){
print $row['username']."\t\t";
print $row['fname']."\t\t";
print $row['lname']."\n";
}
echo '</pre>';
?>
foreach($db_connection->query($query) as $row){
print $row['username']."\t\t";
print $row['fname']."\t\t";
print $row['lname']."\n";
}
echo '</pre>';
?>
</body> </body>
</html> </html>
<?php
$db_connection = null;
?>