Lots and lots of stuff...
This commit is contained in:
@@ -1,13 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
$server = "localhost";
|
$server = "localhost";
|
||||||
$database = "friendBook";
|
$database = "friendBook";
|
||||||
$username = "web";
|
$username = "web";
|
||||||
$password = "Password456";
|
$password = "Password456";
|
||||||
|
|
||||||
// Current user
|
|
||||||
$user = "William"; // Testing with until we have login working
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<html>
|
<html>
|
||||||
@@ -16,34 +13,51 @@ $user = "William"; // Testing with until we have login working
|
|||||||
<body>
|
<body>
|
||||||
<h1>PHP Test Page</h1>
|
<h1>PHP Test Page</h1>
|
||||||
|
|
||||||
<h2>Connecting to MySQL</h2>
|
<h2>MySQL</h2>
|
||||||
|
|
||||||
|
<h3>Creating Connection</h3>
|
||||||
<?php
|
<?php
|
||||||
try{
|
try{
|
||||||
$connection = new PDO("mysql:host=$server;dbname=$database", $username, $password);
|
$connection = new PDO("mysql:host=$server;dbname=$database", $username, $password);
|
||||||
// set the PDO error mode to exception
|
// set the PDO error mode to exception
|
||||||
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||||
echo "Connected successfully";
|
echo "Connected successfully".PHP_EOL;
|
||||||
}
|
}
|
||||||
catch(PDOException $e){
|
catch(PDOException $e){
|
||||||
echo "Connection failed: " . $e->getMessage();
|
echo "Connection failed: ".$e->getMessage().PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "SELECT messageID, date, message
|
|
||||||
FROM messages
|
|
||||||
WHERE recipient=$user";
|
|
||||||
foreach($connection->query($sql) as $row){
|
|
||||||
print $row['messageID'] . "\t";
|
|
||||||
print $row['date'] . "\t";
|
|
||||||
print $row['message'] . "\t";
|
|
||||||
}
|
|
||||||
|
|
||||||
$conn = null;
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<h2>PHP Session Info</h2>
|
<h3>Creating and Executing Query</h3>
|
||||||
<?php
|
<?php
|
||||||
print_r($_SESSION);
|
try{
|
||||||
|
$sql = "SELECT messageID, date, message FROM messages WHERE recipient={$_SESSION["loggedInUser"]}";
|
||||||
|
foreach($connection->query($sql) as $row){
|
||||||
|
print $row['messageID']."\t";
|
||||||
|
print $row['date']."\t";
|
||||||
|
print $row['message']."\t";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception $e){
|
||||||
|
echo "Error: ".$e->getMessage().PHP_EOL;
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<h3>$sql</h3>
|
||||||
|
<?php
|
||||||
|
echo "<pre>";
|
||||||
|
print_r($sql);
|
||||||
|
echo "</pre>";
|
||||||
|
?>
|
||||||
|
|
||||||
|
<h3>$_SESSION</h3>
|
||||||
|
<?php
|
||||||
|
echo "<pre>";
|
||||||
|
print_r($_SESSION);
|
||||||
|
echo "</pre>";
|
||||||
?>
|
?>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
$connection = null;
|
||||||
|
?>
|
||||||
Reference in New Issue
Block a user