Lots and lots of stuff...
This commit is contained in:
@@ -1,13 +1,10 @@
|
||||
<?php
|
||||
session_start();
|
||||
session_start();
|
||||
|
||||
$server = "localhost";
|
||||
$database = "friendBook";
|
||||
$username = "web";
|
||||
$password = "Password456";
|
||||
|
||||
// Current user
|
||||
$user = "William"; // Testing with until we have login working
|
||||
$server = "localhost";
|
||||
$database = "friendBook";
|
||||
$username = "web";
|
||||
$password = "Password456";
|
||||
?>
|
||||
|
||||
<html>
|
||||
@@ -15,35 +12,52 @@ $user = "William"; // Testing with until we have login working
|
||||
</head>
|
||||
<body>
|
||||
<h1>PHP Test Page</h1>
|
||||
|
||||
<h2>Connecting to 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";
|
||||
}
|
||||
catch(PDOException $e){
|
||||
echo "Connection failed: " . $e->getMessage();
|
||||
}
|
||||
|
||||
$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;
|
||||
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;
|
||||
}
|
||||
?>
|
||||
|
||||
<h2>PHP Session Info</h2>
|
||||
<h3>Creating and Executing Query</h3>
|
||||
<?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>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
<?php
|
||||
$connection = null;
|
||||
?>
|
||||
Reference in New Issue
Block a user