From 0c59c98d7529af8f1b3c7bd9030f93221fcb5278 Mon Sep 17 00:00:00 2001 From: William Miceli Date: Tue, 3 Dec 2019 04:41:39 -0500 Subject: [PATCH] Major re-work of things... --- var/www/debug.php | 68 +++++++++++++++++------------------ var/www/friends.php | 88 ++++++++++++++++++++++----------------------- 2 files changed, 77 insertions(+), 79 deletions(-) diff --git a/var/www/debug.php b/var/www/debug.php index 7e6d870..120f015 100644 --- a/var/www/debug.php +++ b/var/www/debug.php @@ -11,56 +11,54 @@

MySQL

-

Creating Connection

- setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - echo "Connected successfully".PHP_EOL; - } - catch(PDOException $e){ - echo "Connection failed: ".$e->getMessage().PHP_EOL; - } - ?> -

Creating and Executing Query

query($sql) as $row){ - print $row['messageID']."\t"; + echo '
';
+                echo "messageID\tdate\t\tsender\trecipient\tmessage\n\n";
+                $sql_select = "SELECT messageID, date, sender, recipient, message";
+                $sql_from = "FROM messages";
+                $sql_where = "WHERE recipient='".$_SESSION["loggedInUser"]."' OR sender='".$_SESSION["loggedInUser"]."'";
+                $sql_order = "ORDER BY messageID";
+                $sql_statement = $sql_select." ".$sql_from." ".$sql_where." ".$sql_order;
+                foreach($db_connection->query($sql_statement) as $row){
+                    print $row['messageID']."\t\t";
                     print $row['date']."\t";
-                    print $row['message']."\t";
+                    print $row['sender']."\t";
+                    print $row['recipient']."\t\t";
+                    print $row['message']."\n";
                 }
+                echo '
'; + }catch(PDOException $e){ + echo "PDOException: ".$e->getMessage().PHP_EOL; + }catch(Exception $e){ + echo "Exception: ".$e->getMessage().PHP_EOL; } - catch(Exception $e){ - echo "Error: ".$e->getMessage().PHP_EOL; - } - ?> -

$sql

- Variables'; + + echo '

$sql

'; echo "
";
             print_r($sql);
             echo "
"; - ?> -

$_POST

- "; - print_r($_POST); - echo ""; - ?> + $superglobalsList = array('$_SERVER','$_REQUEST','$_POST','$_GET','$_FILES','$_ENV','$_COOKIE','$_SESSION'); + foreach($superglobalsList as $value){ + echo "

$value

"; + echo '
';
+                print_r(eval('return '.$value.';'));
+                echo '
'; + } -

$_SESSION

- Like, everything everything?...'; + echo '

$GLOBALS

'; echo "
";
-            print_r($_SESSION);
+            print_r($GLOBALS);
             echo "
"; ?> \ No newline at end of file + $db_connection = null; +?> diff --git a/var/www/friends.php b/var/www/friends.php index 85af602..8a2872f 100644 --- a/var/www/friends.php +++ b/var/www/friends.php @@ -1,48 +1,48 @@ - - - - - -

Friend List

- 0) -{ - // output data of each row - while($row = mysqli_fetch_assoc($result)) - { - echo "friends: " . $row["friend"]. ; - echo "
"; - } -} -else -{ - echo "0 results"; -} - + session_start(); + require 'db_connection.php'; ?> - - + + + + FriendBook Friends + + + + + '; +// echo "messageID\tdate\t\tsender\trecipient\tmessage\n\n"; + $sql_select = "SELECT friend"; + $sql_from = "FROM friendList"; + $sql_where = "WHERE username='".$_SESSION["loggedInUser"]."' AND confirm=true"; + $sql_order = "ORDER BY friend"; + $sql_statement = $sql_select." ".$sql_from." ".$sql_where." ".$sql_order; + foreach($db_connection->query($sql_statement) as $row){ + print $row['friends']."\n"; + } + echo ''; + }catch(PDOException $e){ + echo "PDOException: ".$e->getMessage().PHP_EOL; + }catch(Exception $e){ + echo "Exception: ".$e->getMessage().PHP_EOL; + } + echo '

$GLOBALS

'; + echo '
';
+            print_r($GLOBALS);
+            echo '
'; + + ?> + + +