Major re-work of things...
This commit is contained in:
@@ -11,56 +11,54 @@
|
|||||||
|
|
||||||
<h2>MySQL</h2>
|
<h2>MySQL</h2>
|
||||||
|
|
||||||
<h3>Creating Connection</h3>
|
|
||||||
<?php
|
|
||||||
try{
|
|
||||||
$connection = new PDO("mysql:host=$server;dbname=$database", $username, $password);
|
|
||||||
// set the PDO error mode to exception
|
|
||||||
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
||||||
echo "Connected successfully".PHP_EOL;
|
|
||||||
}
|
|
||||||
catch(PDOException $e){
|
|
||||||
echo "Connection failed: ".$e->getMessage().PHP_EOL;
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
|
|
||||||
<h3>Creating and Executing Query</h3>
|
<h3>Creating and Executing Query</h3>
|
||||||
<?php
|
<?php
|
||||||
try{
|
try{
|
||||||
$sql = "SELECT messageID, date, message FROM messages WHERE recipient={$_SESSION["loggedInUser"]}";
|
echo '<pre>';
|
||||||
foreach($connection->query($sql) as $row){
|
echo "messageID\tdate\t\tsender\trecipient\tmessage\n\n";
|
||||||
print $row['messageID']."\t";
|
$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['date']."\t";
|
||||||
print $row['message']."\t";
|
print $row['sender']."\t";
|
||||||
|
print $row['recipient']."\t\t";
|
||||||
|
print $row['message']."\n";
|
||||||
}
|
}
|
||||||
|
echo '</pre>';
|
||||||
|
}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;
|
echo '<h1>Variables</h1>';
|
||||||
}
|
|
||||||
?>
|
echo '<h3>$sql</h3>';
|
||||||
<h3>$sql</h3>
|
|
||||||
<?php
|
|
||||||
echo "<pre>";
|
echo "<pre>";
|
||||||
print_r($sql);
|
print_r($sql);
|
||||||
echo "</pre>";
|
echo "</pre>";
|
||||||
?>
|
|
||||||
|
|
||||||
<h3>$_POST</h3>
|
$superglobalsList = array('$_SERVER','$_REQUEST','$_POST','$_GET','$_FILES','$_ENV','$_COOKIE','$_SESSION');
|
||||||
<?php
|
foreach($superglobalsList as $value){
|
||||||
echo "<pre>";
|
echo "<h3>$value</h3>";
|
||||||
print_r($_POST);
|
echo '<pre>';
|
||||||
echo "</pre>";
|
print_r(eval('return '.$value.';'));
|
||||||
?>
|
echo '</pre>';
|
||||||
|
}
|
||||||
|
|
||||||
<h3>$_SESSION</h3>
|
echo '<h2> Like, everything everything?...</h2>';
|
||||||
<?php
|
echo '<h3>$GLOBALS</h3>';
|
||||||
echo "<pre>";
|
echo "<pre>";
|
||||||
print_r($_SESSION);
|
print_r($GLOBALS);
|
||||||
echo "</pre>";
|
echo "</pre>";
|
||||||
?>
|
?>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
$connection = null;
|
$db_connection = null;
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -1,48 +1,48 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<body>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: #3B5998;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<h2><font color="white">Friend List</h2>
|
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
$servername = "localhost";
|
session_start();
|
||||||
$username = "web";
|
require 'db_connection.php';
|
||||||
$password = "Password456";
|
|
||||||
$dbname = "computer";
|
|
||||||
|
|
||||||
// Create connection
|
|
||||||
$conn = mysqli_connect($servername, $username, $password, $dbname);
|
|
||||||
// Check connection
|
|
||||||
if (!$conn)
|
|
||||||
{
|
|
||||||
die("Connection failed: " . mysqli_connect_error());
|
|
||||||
}
|
|
||||||
|
|
||||||
$sql = "SELECT friend FROM friendlist WHERE username = 'user1' and confirm = true";
|
|
||||||
$result = mysqli_query($conn, $sql);
|
|
||||||
|
|
||||||
|
|
||||||
if (mysqli_num_rows($result) > 0)
|
|
||||||
{
|
|
||||||
// output data of each row
|
|
||||||
while($row = mysqli_fetch_assoc($result))
|
|
||||||
{
|
|
||||||
echo "friends: " . $row["friend"]. ;
|
|
||||||
echo "<br>";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
echo "0 results";
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
</body>
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||||
</html>
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||||
|
<head>
|
||||||
|
<title>FriendBook Friends</title>
|
||||||
|
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
background-color: #3B5998;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<?php
|
||||||
|
try{
|
||||||
|
echo '<pre>';
|
||||||
|
// 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 '</pre>';
|
||||||
|
}catch(PDOException $e){
|
||||||
|
echo "PDOException: ".$e->getMessage().PHP_EOL;
|
||||||
|
}catch(Exception $e){
|
||||||
|
echo "Exception: ".$e->getMessage().PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo '<h3>$GLOBALS</h3>';
|
||||||
|
echo '<pre>';
|
||||||
|
print_r($GLOBALS);
|
||||||
|
echo '</pre>';
|
||||||
|
|
||||||
|
?>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
<?php
|
||||||
|
$db_connection = null;
|
||||||
|
?>
|
||||||
|
|||||||
Reference in New Issue
Block a user